how to map xml element to bean property by an attribute and not by its name using betwixt?
the xml开发者_如何学JAVA contains:
<rc ix="attr1">value1</rc> <rc ix="attr2">value2</rc>and the bean has 2 properties:
String prop1; String prop2;Does anyone know how can i map this in a .betwixt file?
Also i can only use betwixt...<class name="package.name.ClassName">
<element name="rc">
<attribute name="attr1" property="nameOfProperty1" />
<element name="value" property="theFieldValue1MapsTo" />
</element>
</class>
Something in that sense. Betwixt has a nasty habit of not warning you about errors. To ensure you get the debug log set the log level on betwixt to TRACE
or INFO
.
Furthermore you must ensure all properties/attributes have public
getters and setters with no side-effects. If they are protected
or anything less visible, they will simply be ignored.
The naming convention for the getters and setters is the standard Java convention. In other words boolean getters/setters are allowed to be called isSomeBooleanValue
and setSomeBooleanValue
.
Betwixt is very picky and has not been supported since '08 I think, if you can, switch to JAXB or similar.
精彩评论