Adam Bien's Weblog

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: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.

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


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

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 #

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