Skip to main content

problem with serialization of objects with @XmlID

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

Hi,
I have an class which has an @XmlID annotation.
-------------
@XmlType
@XmlRootElement(name="ti")
@XmlAccessorType(AccessType.FIELD)
public class TestInterfaceImpl implements TestInterface {

@XmlID
String s;

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

public TestInterfaceImpl() {
super();
vvv=""+System.currentTimeMillis();
}

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:

@XmlIDREF
private TestInterfaceImpl ti;

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

aaa
ddd

----

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.
sekhar
Offline
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.

ramazanyich2
Offline
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.