我有一个非常简单的问题:
假设我有一个这样定义的模型类:
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 的标准设置器,但 getter 有一个不同的名称:getFormattedTestProperty()。
是否可以在 Jaxb/Moxy 中指定用于特定属性的吸气剂?
我正在使用带有外部元数据绑定文件的 MOXy 实现。我正在从事的项目使用您使用 Castor。在 Castor 的映射文件中,您可以指定使用哪个 getter/setter:
<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" />
请注意,我对模型类的控制非常有限。
提前感谢您的回答。