Skip to main content

problem with serialization of objects with @XmlID

2 replies [Last post]
Joined: 2005-09-05

I have an class which has an @XmlID annotation.
public class TestInterfaceImpl implements TestInterface {

String s;

String vvv;
public String getVvv() {
return vvv;
public void setVvv(String vvv) {
this.vvv = vvv;

public TestInterfaceImpl() {

public String getS() {
return s;
public void setS(String s) {
this.s = s;
public void doSomeThing(String s, String b) {



In another class (TestClass) I have that class as member:

private TestInterfaceImpl ti;

Then I serialize it only s String of TestInterfaceImpl is serialized.
But then I remove @XmlIDREF annotation then all members of TEstInterfaceImpl are serialized.



why then I use @XMLIDref only the member with @XMLID annotation is serialized ? Is it according to specification ? or it is a bug ?

Reply viewing options

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

It is according to the spec.

See the javadoc for @javax.xml.bind.annotation.XmlIDREF
In particular take a look at example 2 in the javadoc for @XmlIDREF annotation . This is a detailed example that shows the use of @XmlID and @XmlIDREF.

Note: At least one class in your application must reference TestInterfaceImpl by containment (i.e. without @XmlIDREF annotation). Otherwise the XML instance that is marshalled will contain only references to TestInterfaceImpl which will be unresolved.

Joined: 2005-09-05

What I want to do is quite simple: I have one object which is referenced from other objects. And during serialization/desirialization I want that this object will be the same (same hashcode) in all objects that are reference it.