非常に簡単な質問があります:
次のように定義されたモデルクラスがあるとします。
public class Test{
private String testAttribute;
public Test(){
}
public String getFormattedTestAttribute(){
return testAttribute + "A nice formatted thingy"; //right, this is just an example
}
public void setTestAttribute(String value){
testAttribute = value;
}
}
testPropertyの標準セッターがありますが、ゲッターの名前はgetFormattedTestProperty()であることがわかります。
Jaxb / Moxyで、特定のプロパティに使用するゲッターを指定することはできますか?
外部メタデータバインディングファイルでMOXy実装を使用しています。私が取り組んでいるプロジェクトは、Castorを使用しています。Castorのマッピングファイルに、次のように使用するゲッター/セッターを指定できます。
<field name="testAttribute"
get-method="getFormattedTestAttribute">
<bind-xml name="test-attribute" node="attribute"/>
</field>
moxyの外部メタデータでも同じようなことが可能ですか?
そのようなカスタマイズがサポートされていない場合、フィールドを読み取り専用としてマークし、別のフィールドを書き込み専用としてマークすることは可能ですか?したがって、「formattedTestAttribute」という名前の読み取り専用プロパティと「testAttribute」という名前の書き込み専用プロパティをメタデータバインディングファイルに宣言できますか?
<!-- read only property -->
<xml-element java-attribute="formattedTestAttribute" xml-path="@test-attribute" />
<!-- write only property -->
<xml-element java-attribute="testAttribute" xml-path="@test-attribute" />
モデルクラスの制御は非常に限られていることに注意してください。
よろしくお願いします。