Feel free to send me more details about your setup through the Contact Me page on this blog. -Blaise Reply Delete Replies Reply Anonymous December 20, 2010 at 7:58 AM The MyMapAdapter does not compile imcompatible types found: java.lang.Object required: java.util.Map.Entry for (Entry entry: arg0.entrySet()) Reply Delete Replies Reply Blaise Doughan December 20, 2010 at 10:10 AM The compilation issue should be fixed now.
Marshallinghttpmessageconverter Spring Example How To Use XmlAdapterHowever there appears to be some confusion on how to use XmlAdapter, below is the general concept: Identify the unmappable class.
Marshallinghttpmessageconverter Spring Example Free To SendBelow Ill flush out the example used there. Identify the Unmappable Class In this example the unmappable class is java.util.Map. Create an Equivalent Class that is Mappable Map could be represented by an object (MyMapType), that contained a list of objects with two properties: key and value (MyMapEntryType). The value type is the mappable class, and the bound type is the unmappable class. Now during marshalunmarshal operations the instance of Map is treated as an instance of MyHashMapType. Further Reading If you enjoyed this post, then you may also be interested in: JAXB and Immutable Objects In this post an XmlAdapter is used map a domain object with a mult-argument constructor and fields marked final. This example also demonstrates how the XmlJavaTypeAdapter annotation can be used at the type level. I have complex data structures such as Vector and HashMap i.e. Could you please help me on how I should marshallunmarshall Reply Delete Replies Reply Blaise Doughan October 13, 2010 at 12:04 PM The process would be very similar. Vector Inside a HashMap If we consider you case with a Vector inside a HashMap. You would change the MyMapEntryType so that the value property was a Vector. Vector Inside a Vector For this use case your intermediate object would be a Vector of Value objects, each Value Object would have a value property representing the nested Vector. Reply Delete Replies Reply Carlos November 12, 2010 at 11:33 AM Great post Blaise Im using XMLAdapter with a List, but Im having a problem. Marshalling the entities of the List, the tags are replaced by A Customer as some attibutes (id, name,.) and a DocumentSet (basically a List). ![]() In your example you are converting to a String that contains XML markup. Instead you should convert to an object that would produce the desired XML. Some of the details of your message were lost due to the XML escaping aspect of this blog. Feel free to message me from the blog with about this issue: - -Blaise Reply Delete Replies Reply Bogdan Marian November 18, 2010 at 2:54 AM Very nice article I was wondering, if my JAXB annotated classes are generated based on a given XSD file, how can I specify my adapters, knowing that every time I changed the XSD file, all classes will also be regenerated Reply Delete Replies Reply Blaise Doughan November 18, 2010 at 2:05 PM Hi Bogdan, The XmlAdapter mechanism is used when starting with Java classes and you have an unmappable class. When you start from an XML schema, the JAXB schema compiler tool (XJC) generates compatible classes, no XmlAdapter is necessary. Blaise Reply Delete Replies Reply Blaise Doughan November 19, 2010 at 10:54 AM Hi Carlos, Thank you for sending me the sample code. I have just emailed you an example that demonstrates how XmlAdapter could be used. I do not recommend the approach that you are attempting where the adapted type is a String that contains XML markup. You may be able to make this work with streams, but it will not work when dealing with DOMSAXStAX inputs and outputs. Blaise Reply Delete Replies Reply Unknown November 23, 2010 at 12:41 AM Hi Blaise, Im encoutering an issue, where the objects generated from JAXB (through Maven) having no no-arg constructors on Windows couldnt work when theyre deployed in server on Linux during creation of JAXBContext - complaining of no no-arg public constructor. Is that something XmlAdapter could resolve Thanks, - John Reply Delete Replies Reply Blaise Doughan November 23, 2010 at 2:48 PM Hi John, It is common to use an XmlAdapter for classes that do not have a no-arg constructor. However, JAXB should not be creating classes without a no-arg constructor. Feel free to send me more details about your setup through the Contact Me page on this blog. Blaise Reply Delete Replies Reply Anonymous December 20, 2010 at 7:58 AM The MyMapAdapter does not compile imcompatible types found: java.lang.Object required: java.util.Map.Entry for (Entry entry: arg0.entrySet()) Reply Delete Replies Reply Blaise Doughan December 20, 2010 at 10:10 AM The compilation issue should be fixed now.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |