开发者

JAXB marshalling/unmarshalling without any configuration

I'm trying to marshal/unmarshal Java ValueObject class through JAXB.

To do it, I found that it requires XML Schema file and ObjectFactory class that can be automatically c开发者_如何学运维reated by ant.

If so, it seems to be able to get marshaled/unmarshaled WITHOUT XML Schema file and ObjectFactory, because they can be automatically created.

But as long as I researched, somehow JAXB doesn't provide the way.

Do you know any way to do it?


JAXB does not require a schema, it is designed to start from Java objects. You then add annotations to customize the mapping to XML. Below are some useful examples to get started:

  • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted

Check out my blog for more JAXB examples that start with Java objects:

  • http://bdoughan.blogspot.com


Your understanding is partially correct in my opinion. If you are starting from the Java ValueObject class, then there is no need for schema...you can refer to the example pointed by Blaise. But sometimes, the ValueObject class is not given to you. Instead an xml schema definition is given. So using ANT as you say....you can generate the ValueObject class from the xml schema.

So to iterate, in your case, since you have ValueObject already, no need for schema


i'm not an expert in JAXB but you can create the unmarshaller whith this constructor:

EDIT- sorry wrong code xD

JAXBContext jaxbContext = JAXBContext.newInstance(Class1.class, Class2.class, ...);
Marshaller marshaller = jaxbContext.createMarshaller();

In this question

Use JAXB unmarshalling in Weblogic Server

You can see that i use a weblogic JAX-RPC autogenerated classes in the unmarshall of a XML. There are not ObjectFactory and this work for me... without attributes. I suposse that JAXB uses reflection to do this. Try to unmarshall with this constructor. If its not a solution use the annotations (follow Blaise link) Think in composition if you can't modify ValueObject class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜