I have a class Organization with few date
fields as follows.
public class Organization {
private String _id;
private String name;
@JsonDeserialize(using=JsonDateDeserializer.class)
@JsonSerialize(using=JsonDateSerializer.class)
private Date createdTime;
// getters and setters
}
To handle the date in simple way on client side I convert date
to long
and send it to client using these JsonSerializer as follows
public class JsonDateSerializer extends JsonSerializer<Date>{
@Override
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException {
gen.writeNumber(date.getTime());
}
}
I have a endpoint which will execute get organization and insert the results in response map like this.
@ApiMethod(name="organization.get", path="organizations/{organizationId}", httpMethod=HttpMethod.GET)
public Map<String, Object> organizationDetails(@Named("organizationId") String organizationId){
Organization org = DB.getOrganization("123");
Map<String, Object> response = new HashMap<String, Object>();
response.put("status", HttpServletResponse.SC_OK);
response.put("success", true);
response.put("entity", org);
return response;
}
But the end resultant JSON I see on client side is
{
"status" : 200,
"entity" : [ {
"_id" : "966a03b3-8e46-41ee-b330-6533409b2b4a",
"name" : "POKURI",
"createdTime" : "2015-05-16T15:02:31.499+05:30"
} ],
"success" : true
}
Here the date coming in some format instead of long. If I convert the same using Jackson ObjectMapper
without using cloud endpoints I am getting response in expected way. Why cloud endpoints not respecting Jackson annotations? Is there a way to configure that?
Note: Even I observed that long
is coming as string on client side if you use cloud endpoints. I am using appengine SDK 1.9.19