2

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 created 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?

kuma
  • 41
  • 1
  • 3

3 Answers3

2

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:

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

bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Thanks, Blaise. But what I really wanted to know was (because of my bad explaination, it couldn't be understood by my post, sorry), the way using JAXB whth NO ADDITIONAL INFO. – kuma Dec 27 '10 at 00:51
  • I'm not sure what you mean. If you check out the examples I linked to you will see JAXB can work with your existing objects. Even without adding annotations. – bdoughan Dec 27 '10 at 12:06
0

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

Victor
  • 16,609
  • 71
  • 229
  • 409
  • Thanks, Kaushik. But what I really wanted to know was (because of my bad explaination, it couldn't be understood by my post, sorry), the way using JAXB whth NO ADDITIONAL INFO. – kuma Dec 27 '10 at 00:45
0

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.

Community
  • 1
  • 1
Leo
  • 75
  • 1
  • 9