users@jersey.java.net

[Jersey] Re: json conversion results in empty object

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Tue, 11 Jan 2011 12:15:36 +0100

I presume, the jersey-json module is present in the classpath,
so the issue was not caused by missing JSON readers/writers, right?

Then to limit the number of moving parts, could you please try to:

- comment out the @XmlType annotation (with the empty name="" param)
- replace the dot from the @XmlRootElement annotation name param
(s/authorize.conf/authorizeconf/)
- introduce a simple @GET method returning an AuthorizeConf instance,
now what do you HTTP GET from it?

~Jakub

On 01/10/2011 12:35 PM, Peter De Koster wrote:
> going from json to normal xml withouth code change makes everything
> work. So it must be something inside the JSON marshall/unmarshall code.
>
>
>
> Hello,
>
> I'm using a class that was generated from an xsd using sun's maven
> plugin. Now I have to use it for a JAX-RS / JERSEY resource in
> json format.
>
>
> Trying this I don't get actual exceptions but the object is
> completely empty after the conversion (so all fields are null),
> whereas the same application is using other jaxb annotated classes
> in resources with json.
>
>
> This class does look strange (it is generated).
>
> Does anyone see anything special about this class:
>
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
> "status",
> "expiryDate",
> "parentIdTag"
> })
> @XmlRootElement(name = "authorize.conf")
> public class AuthorizeConf
> implements Serializable, Equals, HashCode, ToString
> {
>
> private final static long serialVersionUID = 2L;
> @XmlElement(required = true)
> protected AuthorizationStatus status;
> @XmlElement(required = true, type = String.class)
> @XmlJavaTypeAdapter(DateAdapter.class)
> @XmlSchemaType(name = "date")
> protected Date expiryDate;
> protected String parentIdTag;
>
> /**
> * Gets the value of the status property.
> *
> * @return
> * possible object is
> * {_at_link AuthorizationStatus }
> *
> */
> public AuthorizationStatus getStatus() {
> return status;
> }
>
> /**
> * Sets the value of the status property.
> *
> * @param value
> * allowed object is
> * {_at_link AuthorizationStatus }
> *
> */
> public void setStatus(AuthorizationStatus value) {
> this.status = value;
> }
>
> /**
> * Gets the value of the expiryDate property.
> *
> * @return
> * possible object is
> * {_at_link String }
> *
> */
> public Date getExpiryDate() {
> return expiryDate;
> }
>
> /**
> * Sets the value of the expiryDate property.
> *
> * @param value
> * allowed object is
> * {_at_link String }
> *
> */
> public void setExpiryDate(Date value) {
> this.expiryDate = value;
> }
>
> /**
> * Gets the value of the parentIdTag property.
> *
> * @return
> * possible object is
> * {_at_link String }
> *
> */
> public String getParentIdTag() {
> return parentIdTag;
> }
>
> /**
> * Sets the value of the parentIdTag property.
> *
> * @param value
> * allowed object is
> * {_at_link String }
> *
> */
> public void setParentIdTag(String value) {
> this.parentIdTag = value;
> }
>
> public void toString(ToStringBuilder toStringBuilder) {
> {
> AuthorizationStatus theStatus;
> theStatus = this.getStatus();
> toStringBuilder.append("status", theStatus);
> }
> {
> Date theExpiryDate;
> theExpiryDate = this.getExpiryDate();
> toStringBuilder.append("expiryDate", theExpiryDate);
> }
> {
> String theParentIdTag;
> theParentIdTag = this.getParentIdTag();
> toStringBuilder.append("parentIdTag", theParentIdTag);
> }
> }
>
> public String toString() {
> final ToStringBuilder toStringBuilder = new
> JAXBToStringBuilder(this);
> toString(toStringBuilder);
> return toStringBuilder.toString();
> }
>
> public void equals(Object object, EqualsBuilder equalsBuilder) {
> if (!(object instanceof AuthorizeConf)) {
> equalsBuilder.appendSuper(false);
> return ;
> }
> if (this == object) {
> return ;
> }
> final AuthorizeConf that = ((AuthorizeConf) object);
> equalsBuilder.append(this.getStatus(), that.getStatus());
> equalsBuilder.append(this.getExpiryDate(),
> that.getExpiryDate());
> equalsBuilder.append(this.getParentIdTag(),
> that.getParentIdTag());
> }
>
> public boolean equals(Object object) {
> if (!(object instanceof AuthorizeConf)) {
> return false;
> }
> if (this == object) {
> return true;
> }
> final EqualsBuilder equalsBuilder = new JAXBEqualsBuilder();
> equals(object, equalsBuilder);
> return equalsBuilder.isEquals();
> }
>
> public void hashCode(HashCodeBuilder hashCodeBuilder) {
> hashCodeBuilder.append(this.getStatus());
> hashCodeBuilder.append(this.getExpiryDate());
> hashCodeBuilder.append(this.getParentIdTag());
> }
>
> public int hashCode() {
> final HashCodeBuilder hashCodeBuilder = new
> JAXBHashCodeBuilder();
> hashCode(hashCodeBuilder);
> return hashCodeBuilder.toHashCode();
> }
>
> public AuthorizeConf withStatus(AuthorizationStatus value) {
> setStatus(value);
> return this;
> }
>
> public AuthorizeConf withExpiryDate(Date value) {
> setExpiryDate(value);
> return this;
> }
>
> public AuthorizeConf withParentIdTag(String value) {
> setParentIdTag(value);
> return this;
> }
>
> }
>
> I'm having this problem in my unit test in which I perform
> something like:
>
> webresource.type(APPLICATION_JSON_TYPE).accept(APPLICATION_JSON_TYPE)
> .put(AuthorizeConf.class, req);
>
>
> Now what's strange here is that the "req" object is of type
> AuthorizeReq, is generated in the same way and has the exact same
> problem. But I solved it adding a @Provider class (just using
> natural, so I don't know why it helps), this only gets me past
> reading the req object. The authorizeconf object is still wrong.
> What's wrong with this class? Or does the empty object problem
> ring any bell in general ?
>
> The problem occurs with jersey 1.1.5 & 1.4 . Normal Jaxb
> marshalling & unmarshalling of these objects works.
>
> --
> Please think about our environment before considering printing
> this mail.
>
>
>
>
>
>
>
>
> --
> Please think about our environment before considering printing this mail.
>