0

I am using RestEasy to marchal entities to JSON. That works okay but somehow every thing is represented as a String. e.g.

@XmlRootElement(name="TestObject")
public class TestObject {
    private Long value;
    public Long getValue(){
        return value;
    }
}

Instead of creating something like: {TestObject:{value:1234}}

It creates {TestObject:{value:"1234"}} (Please note the " " around the number)

So the long value is converted into a String. How can I avoid that?

I've asked on the Jackson forum which RestEasy is using for the JSON marchaling but they said it is probably caused by going Java->XML->JSON. There doesn't seem to be a RestEasy forum and on the Seam forum no one could answer my question.

Does anyone else have the same problem?

Regards

2 Answers 2

1

Okay the problem is that RestEasy+Seam uses Jettison by default (and not Jackson). Jettison does the marchaling via Java->XML->JSON.

The Jackson jars aren't actually included in the Seam distribution so you have to download RestEasy and copy all jars which mention jackson to your lib directory. When RestEasy finds the resteasy-jackson-provider.jar in the classpath, Jackson will be used instead of Jettison.

One problem I had when moving to Jackson from Jettison were cycling references. With Jettison you just annotate the method (e.g. a @ManyToOne relationship) with @XmlTransient. For Jackson you have to annotate it with @JsonIgnore

2
  • If this is the answer to your question, then please mark it as accepted so it doesnt appear in the unanswered part Oct 4, 2010 at 14:15
  • No it is not fully answered, it is only a workaround. When using Jackson instead of Jettison with RestEASY you get the problem that arrays aren't labeled which I need. I guess RestEASY is mainly tested with Jettison. Jackson supports labelling of arrays by using @JsonTypeInfo but somehow that gets lost when RestEASY does the wrapping.
    – Ben
    Oct 20, 2010 at 14:26
1

use

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jettison-provider</artifactId>
    <version>2.0.1.GA</version>
    <exclusions>
        <exclusion>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
        </exclusion>
        <exclusion>
            <groupId>javax.xml.stream</groupId>
            <artifactId>stax-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

I use only resteasy-jettison-provider, but server hangs when I try to get JSON output, but after I excludes the jaxb-api and jaxb-impl. webservice works perfectly fine with JSON output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.