views:

85

answers:

1

Hi,

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

A: 

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

Ben
If this is the answer to your question, then please mark it as accepted so it doesnt appear in the unanswered part
Shervin
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