HappyEngineer
HappyEngineer

Reputation: 4055

JAXB is good until I need to do something complex. What are the alternatives?

JAXB works well until I need to do something like serialize beans for which I cannot modify the source. If the bean doesn't have a default constructor or if it refers to objects I want to mark transient then I'm stuck writing a separate bean which I can annotate and then manually copy the information over from the other bean.

For instance, I wanted to serialize exception objects, but found that the only way to do that was use a hack that required using com.sun.* classes.

So, what alternatives are there? What's the next most popular xml serializing api? It would be nice to be able to do things like:

Basically I just want more flexibility than I currently have with JAXB.

Upvotes: 6

Views: 918

Answers (2)

bdoughan
bdoughan

Reputation: 148977

JAXB is a spec, so you can pick from different implementations. EclipseLink JAXB (MOXy) has extensions for what you are asking:

Externalized Metadata

Useful when dealing with classes for which you cannot annotate the source or to apply multiple mappings to an object model.

XPath Based Mapping

For true meet-in-the-middle OXM mapping:

JPA Compatibility

Including support for bi-directional relationships.

Upvotes: 2

Chris Kessel
Chris Kessel

Reputation: 5875

Also look at JIBX. It's a good xml<->object mapper. My experience is though that if your objects have a somewhat funky relationships it's often easier to create a wrapper object that hides that complexity and then map that object with JIBX.

Upvotes: 1

Related Questions