Hi
On 17/05/13 12:36, Zach Calvert wrote:
Hello,
I'm using Apache CXF Bundle jar version 2.3.2, so I know I'm behind in
versions, but I've yet to come across a bug that identifies my current
problem.
I have the following class hierarchy:
public class A {
protected long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
public class B extends A {
private String guid;
public String getGuid() {
return guid;
}
public void setGuid(String guid) {
this.guid = guid;
}
}
Now, my problem is that I want my XML JSON support to look like
{"id":"guid content"}
Where I'm marshalling B, and the ID field represented in the JSON is
actually set in the guid value of A. The JSON marhsall and unmarshall
should be ignorant and uncaring of the true "ID" field in class type A. If
you're guessing what I'm doing here, A is a hibernate entity and B is what
is reflected to the user. I do not want to expose the actual ID field of A
in my JSON, nor do I want to have to write a new class B to support the
marshalling. I do not have access to update the annotations on A, so all
of my annotating can only be done on class B. There are no Xml annotations
on class A.
I have tried
@XmlAccessorType(XmlAccessType.NONE) on class B and I still get the ID
content in my JSON.
I have tried
@XmlType(propOrder = {"guid"})
on class B and still get the ID content in my JSON. Suprisingly, if I add
a bug field like @XmlType(propOrder = {"guid", "garbage"}) to my prop
order, JSON will throw up an exception at me, but if I keep it neat and
clean to just guid, I still get both {"id":1,"guid":"guid content"} when I
demarshall an instance of B.
I have tried
@Override
@XmlTransient
public Long getId() {
return super.getId();
}
and still get the ID field in my JSON. Frankly, it looks like none of my
annotations on class B are overriding the fact that class A exposes a field
called ID.
Is there a manual way to tell the provider "hey, I really really really
don't want you to marshall this ID field"?
In CXF 2.3.2, you can configure JSONProvider with an outDropElements
property, see:
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-CustomizingJAXBXMLandJSONinputandoutput
HTH, Sergey
Thank you,
Zach Calvert