Skip to main content

Unmarshalling using schema generated code from different packages

3 replies [Last post]
bencal
Offline
Joined: 2005-09-06

I have two independant schemas. I compiled each of them in different packages.

The first of them contains an xsd:any element.
The elements of the second schema are included in the xsd:any element of the first schema.

With the following tricks, I can marshall my object tree.

Making the NamespaceContext2 class of the second class inherit from the NamespaceContext2 class from the 1 schema.

Making the XMLSerializer class of the second class inherit from the XMLSerializer class from the 1 schema.

Making the XMLSerializable class of the second class inherit from the XMLSerializable class from the 1 schema.

in JAXBContext.newInstance, passing the package name of both schemas.

But unmarshalling makes a problem.

The unmarshalling mechanism is unable to find the unmarshaller class for the second schema.

I think that the grammar info for the second schema is not loaded in the context.

My code :
"
JAXBContext context = JAXBContext.newInstance("org.util.text.parser.ebnf.jaxb:org.util.parser.importer.sablecc.jaxb:org.util.w3c.xslt.jaxb");
Unmarshaller u = context.createUnmarshaller();
u.unmarshal(input);
"

Is it possible to solve this in an easy way like
customizing binding or calling some methods to merge grammars manually ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09

You shouldn't have to do any of those tricks.
JAXB RI can merge two packages automatically if you just do:
[code]
JAXBContext context = JAXBContext.newInstance("org.util.text.parser.ebnf.jaxb:org.util.parser.importer.sablecc.jaxb:org.util.w3c.xslt.jaxb");
Unmarshaller u = context.createUnmarshaller();
u.unmarshal(input);
[/code]
If that doesn't work, consider using the "-use-runtime" option of XJC to just have one copy of the impl.runtime classes.

(This is 1.0.x issue, right?)

bencal
Offline
Joined: 2005-09-06

You are right, using -use-runtime solve the the marshalling problem but unmarshalling is still a problem.

using "-use-runtime" is necessary because it tells to the code generated to use the runtime code of the foreign package.

This may seem obvious but creating a JAXB context with more than one package is not enough.

[u]Remarks for people willing to try the same kind of things :[/u]
JAXB classes generated with a given runtime is not recognized as being able to be marshalled by JAXB classes generated with another runtime (a runtime placed in another package)

The content of the element containing "" content as viewed by the 1st grammar is not unmarshalled correctly.

JAXB doesn't find any info in its grammarInfo object to spawn an unmarshaller for it.

The grammars seem to not be merged correctly.

[u]PS [/u]: I use the JAXB implementation found in JWSDP 1.5

bencal
Offline
Joined: 2005-09-06

I will first check with the last version of JAXB.

I just saw that I used version 1.0.5