Writing POJOs To XML--Without Annotations

With the utility classes introduced in JDK 1.4 XMLEncoder and XMLDecoder you can serialize and deserialize POJOs with property accessors (aka JavaBeans) with some caveats:

See also other screencasts at: https://tv.adam-bien.com or subscribe to https://www.youtube.com/user/bienadam.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting

Comments:

It's an Encoder and a Decoder, no more no less. If you really want "Writing POJOs To XML" and control the written data you need a lib like XStream (not perfect but good enough).

Posted by javaservant on June 22, 2015 at 09:57 PM CEST #

@JavaServant

or using JAXB: http://www.adam-bien.com/roller/abien/entry/with_pojos_to_xml_and

:-)

cheers,

adam

Posted by Adam Bien on June 23, 2015 at 11:28 AM CEST #

I had seen and read the JAXB entry.
For advanced use cases JAXB certainly isn't the right tool. You cannot combine data sources and cannot change the structure of your data with JAXB. Moreover, you don't want to annotate each and every property with one or more JAXB annotation(s).

I used JAXB for generating objects from a wsdl/schema. JAXB is perfect for this use case. It's inappropriate for creating arbitrary XML files.

Posted by javaservant on June 24, 2015 at 04:19 PM CEST #

Thanks, nice tips

Posted by Binh Nguyen on July 08, 2015 at 03:13 AM CEST #

Thanks, nice tips

Posted by Binh Nguyen on July 08, 2015 at 03:13 AM CEST #

You are Java Duke! thx for your great web place.

Posted by Ladislav Jech on July 21, 2017 at 04:58 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License