views:

159

answers:

1

I have an XSD file which is used to generate some objects which are then shared with other systems. I'd like to customize some of the business logic a bit in there by making some more specific implementation of these. I'm not adding new fields which need to be serialized, but more along the lines of adding setMethods which may take different format parameters. These methods do the work of translating the data into a form which is needed by the underlying object.

I may have a field on the JAXB object which is a string, but my system gives me an integer. So, I want to handle the work of converting that in a class which extends my base class.

So, is there anything special you need to do in order to get JAXB to look for XmlRootElement on a subclass of the object you are asking it to serialize? Or must I include a @XmlRootElement attribute on my more specific class?

thanks!

A: 

Yes, @XmlRootElement/ @XmlType should be enough. But why don't you just add these methods to the generated classes? (in case you are not regenerating them on each build, which is wrong imo)

However I'd advice externalizing the conversion to other (converter) classes / methods.

Bozho
This is because the objects are an "idealized" representation of the data. The data is coming from various systems and needs to be massaged into the idealized format. So, I figured the best solution would be to call methods on a specific object for that implementation which takes care of all the work of making it fit. If you know of a better way, let me know!
jr
Also, I disagree that you shouldn't generate it on each build from XSD. When you do a clean, those generated files should go away. This way you have only one authoritative source and that is the XSD file.
jr