A writeXLM method would return a chunk of XML for that one object, and perhaps contained objects. For example, if my Person class had only one field for name, it might just say:
That approach bakes the ability to build XML right into every class. That doesn't go well with the Single Responsibility Principle, or with repetitive stress disorder from all the typing.
JAXB builds a generic utility with the ability to generate XML for any nicely formed object. You could make your own with reflection to get the class name, field names, field values:
When you find values that are arrays and collections you'd want to iterate them. When you find values that are other objects, you'd want to turn them into nested XML tags. Pretty soon (only a few thousand hours later) you've rewritten JAXB only with your own flavor of bugs. Whee.
So, why no JAXB? I used to have a sign on the wall that said "JAXB must die" so I might agree, but I want to hear your reasons first.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Apr 24, 2007
Hi, I have the business value addressObj say Address (city,state and zip) and this needs to be copied in the AddressImpl(city,state and zip) generated by JAXB to create an XML.
This needs to be done for all the business objects. Is there any better way to do it.
I was unable to follow the following method String toXML(Object obj). If you could give some more details with an example,it would be very helpful.
Joined: Nov 29, 2005
It has already been mentioned as what to do.I will just be repeating the same.
You can have one additional method in you bean class that would return you the chunk of XML that you till now generate using JAXB.
That method can simple return a string have the XML chunk , you would be using the private state variables of you bean class to populate the values within you xml tags.
Hope this helps,
Joined: Jan 29, 2003
I have the business value addressObj say Address (city,state and zip) and this needs to be copied in the AddressImpl(city,state and zip) generated by JAXB to create an XML.
If I understand correctly, I've been in exactly the same boat. We used JAXB to generate classes that exactly matched the XML we used with some partner. But those classes did not match the internal business model in our system. So we had to copy all the fields from the JAXB classes into ours to use the model, then copy them all back from the model into JAXB classes to generate XML.
Does that sound right?
On the parsing side, we threw out JAXB. These were huge messages. JAXB sometimes generated nearly 2,000 classes, and it was less effort to write custom parsers than it was to copy every field. We kept JAXB to generate XML because that part was much smaller, only a few classes.