Reputation: 5388
I am working with Dozer and it is mapping our JAXB objects that are coming from our WebService to business object that reside in the service layer of our application. In some particular cases I need to map codes in String values to human readable description in String values. Example: "FLT" maps to "FLAT" and "TRP" maps to "TRAP". I have a lot of these type mappings.
I am implementing a custom Dozer Converter by inheriting the DozerConverter and implementing the two abstract methods convertTo() and convertFrom(). Within these I wanted to map "FLT" to "FLAT" and "FLAT" to "FLT" respectively but unforunatly Dozer does not call the correct convertTo() or convertFrom() methods correctly.
Does anyone else have this problem and could point me in the right direction? Thanks
Upvotes: 2
Views: 1295
Reputation: 436
If you have control over the POJOs, you could treat these strings as enums. You would have to define enums for the webservice side and the business logic side, but I think it's a more elegant solution than using a converter or xmladapter.
Enum examples:
public enum ENUM_WS {
@XmlEnumValue("TRP") TRAP,
@XmlEnumValue("FLT") FLAT
}
public enum ENUM_BL {
@XmlEnumValue("TRAP") TRAP,
@XmlEnumValue("FLAT") FLAT
}
Upvotes: 2
Reputation: 149047
You could address this issue at the JAXB level. To to this you could leverage an XmlAdapter
that converted the XML string (i.e. FLT) to the object String (i.e. FLAT).
If you are generating your object model from an XML schema the following may help:
Upvotes: 0