Question

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

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top