With POJOs To XML And Back With JAXB

JAXB comes out-of-the-box with JDK and makes it trivial to write and read POJOs from XML:

The entire enhydrator configuration (Pipeline) is persisted with JAXB.

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

Comments:

Hi Adam,

nice example!

Users have to be careful when initializing instance variables within the @Before method because it is executed before *every* @Test method. Especially when test methods are executed in parallel.

IMO instance variables should be declared final. Always. Unfortunately this is not possible in the presence of annotations and dependency injection other than at the constructor level.

Also I do not like setters outside of builders :-) But that is a different Topic.

Cheers

Daniel

Posted by Daniel Dietrich on June 20, 2015 at 11:11 AM CEST #

Hi Adam.
One thing that I always do when using JAXB in Production system, especially if the marshall / unmarshall get called many times, make sure that the JAXB context only gets created once (per POJO) in the runtime of the application. It's a fairly expensive call. (In you case it's done in the test, so not really applicable)

private static JAXBContext jaxbContext = null;
static{
try {
jaxbContext = JAXBContext.newInstance(Duke.class);
} catch (JAXBException e) {
throw new RuntimeException(e);
}
};

Posted by Phillip Kruger on June 21, 2015 at 09:39 AM CEST #

"With POJOs To XML And Back With JAXB"??

Should be: "Write POJOs To XML And Read Back With JAXB".

Posted by javaservant on June 21, 2015 at 10:55 AM CEST #

@javaservant,

your suggestion was my first version. I liked the "with" better.

However: just for you the second episode: http://www.adam-bien.com/roller/abien/entry/writing_pojos_to_xml_without

thanks for the hint!,

adam

Posted by Adam Bien on June 22, 2015 at 01:45 PM CEST #

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