Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problem with ObjectGraph and xml attributes
Problem with ObjectGraph and xml attributes [message #1066187] Mon, 01 July 2013 09:07
Joni Ollila is currently offline Joni Ollila
Messages: 1
Registered: July 2013
Junior Member
Hello

If I have following class hierarchy:

@XmlRootElement(name="test")
@XmlAccessorType(XmlAccessType.FIELD)
class A {
private String fieldA1 = "fieldA1";
private String fieldA2 = "fieldA2";

@XmlElement(name="B")
private B fieldB = new B();
}

class B {
@XmlValue
private String fieldB1 = "fieldB1";

@XmlAttribute(name="fieldB2")
private String fieldB2 = "fieldB2";
}

I get following XML output:

<test>
<fieldA1>fieldA1</fieldA1>
<fieldA2>fieldA2</fieldA2>
<B fieldB2="fieldB2">fieldB1</B>
</test>

Now if I use new ObjectGraph feature:

ObjectGraph graph = JAXBHelper.getJAXBContext(context).createObjectGraph(A.class);
graph.addAttributeNodes("fieldA1", "fieldA2", "fieldB");
marshaller.setProperty(MarshallerProperties.OBJECT_GRAPH, graph);

I get following XML:

<test>
<fieldA1>fieldA1</fieldA1>
<fieldA2>fieldA2</fieldA2>
<B>fieldB1</B>
</test>

As you can see 'fieldB2' annotated with XmlAttribute is missing, but 'fieldB1' annotated with XmlValue is present. Is this really working as it should be? I would like to see in this case also 'fieldB2' there.

This example was simple, but we have quite complicated object structure and it is really pain in the ass if I have to include all attribute fields to 'addAttributeNodes' method.If this is really intended behavior, is there some way to get all the subclass fields (also attributes), when using object graph?

-Joni
Previous Topic:Multiple JPA Persistences loading issue in JBOSS 5
Next Topic:Birt with JBOSS 5 Issue
Goto Forum:
  


Current Time: Thu Apr 17 08:44:06 EDT 2014

Powered by FUDForum. Page generated in 0.02926 seconds