users@jaxb.java.net

Problem with co-existence of JAXB 2.0 objects and JAXB 1.0 objects

From: ysui6888 <yu.sui_at_oracle.com>
Date: Thu, 8 Nov 2007 14:48:55 -0800 (PST)

I have JAXB 2.0 objects referencing some legacy JAXB 1.0 objects. When I
tried to get a marshaller for 2.0 objects, many IllegalAnnotationsException
were raised saying that the 1.0 objects referenced are interface types and
JAXB can't handle interfaces.
 
My understanding of the problem is that
1. JAXB 2.0 objects are all implementation classes. Consequently,
IllegalAnnotationsException would never be raised if all objects involved
were JAXB 2.0 objects.
2. JAXB 1.0 objects have both interface and implementation classes, and they
reference one another through the interface classes. This is not considered
as a problem in JAXB 1.0 framework. IllegalAnnotationsException would never
be raised if all objects involved were JAXB 1.0 objects.
3. The problem is that I have JAXB 2.0 objects referencing JAXB 1.0 objects
through their interface classes, which is considered illegal by JAXB 2.0
framework.
 
I searched the internet for possible solutions to accommodate interfaces in
JAXB 2.0. None of them seems practical for me. For example, the "easiest"
solution is to add a @XMLElement annotation to the place where the interface
is referenced. The @XMLElement annotation would contain a
"type=fooImpl.class" attribute to indicate the implementation class for the
interface, which would prevent the IllegalAnnotationsException from being
raised for the interface. I tried it out and it indeed worked, only to a
limited extent, though.
 
In the following example, my 2.0 object ContextAndCiKeyRequestBaseType
references 1.0 object WorkflowContext, and I used to get an
IllegalAnnotationsException on WorkflowContext being an interface. I added a
"type=WorkflowContextImpl.class" attribute to the already existing
@XMLElement annotation for the workflowContext field:
 
public class ContextAndCiKeyRequestBaseType {
   ...
    @XmlElement(namespace = "xxx", required = true,
type=WorkflowContextImpl.class)
    protected WorkflowContextType workflowContext;
...}
 
 
 and the IllegalAnnotationsException on WorkflowContext being an interface
disappeared. However, I then saw new IllegalAnnotationsException on
interfaces referenced by WorkflowContext, e.g., CredentialType:
 
om.sun.xml.bind.v2.runtime.IllegalAnnotationsException:
...
xxx.CredentialType is an interface, and JAXB can't handle interfaces.
 this problem is related to the following location:
  at xxx.CredentialType
  at public xxx.CredentialType
xxx.WorkflowContextTypeImpl.getCredential()
 
 
It turned out that it is not sufficient for me to modify/annotate my own 2.0
objects where 1.0 objects are referenced. I will need to modify/annotate all
1.0 objects where other 1.0 objects are referenced, which seems to be
problematic.
1. Unlike JAXB 2.0 objects, JAXB 1.0 objects do not physically contain
elements they reference. For example, these is no CredentialType element in
WorkflowContextTypeImpl class. I do not even know where to put the
@XMLElement annotation.
 
public class WorkflowContextTypeImpl ... {

    protected CredentialType credential; ---- No such thing
...}

2. We do not own thelegacy JAXB 1.0 objects and may not be allowed to modify
them.
 
Other potential alternatives such as using XMLJavaTypeAdaptor are even more
complex and intrusive than this @XMLElement approach.
  
Would appreciate any suggestions on how to solve this problem.
-- 
View this message in context: http://www.nabble.com/Problem-with-co-existence-of-JAXB-2.0-objects-and-JAXB-1.0-objects-tf4774226.html#a13657604
Sent from the java.net - jaxb users mailing list archive at Nabble.com.