janetsmith
janetsmith

Reputation: 8732

How to force RESTEasy output number as string in json?

I want to put a quote "" in the following json from RESTEasy (with Jackson).

{
    "isReachable": false,
    "timestamp": 1353449973347
}

{
    "isReachable": "false",
    "timestamp": "1353449973347"
}

The reason why I do that is because I am using GWT, and gwt cannot convert timestamp into long datatype. Do you know how to RESTEasy to output value as string?

Thanks

Upvotes: 1

Views: 431

Answers (1)

gregwhitaker
gregwhitaker

Reputation: 13420

You can annotate the timestamp property in your pojo that you are serializing with the @JsonSerialize annotation and instruct Jackson to use a string serializer.

public class YourPojo
{
     private boolean isReachable = false;

     @JsonSerialize(using = ToStringSerializer.class)
     private Long timestamp;

     //Getters and Setters omitted for brevity
}

Upvotes: 1

Related Questions