I have an object that contains a Calendar type representing the CreatedOn date. I have gotten the adapter to display the milliseconds, but I”m not sure how to output the device configured timezone information as well.
WCF expects dates to be in the following format: "CreatedOn":"\/Date(1305003600000-0500)\/"
This is what I currently have:
Gson gson = new GsonBuilder()
.registerTypeAdapter(GregorianCalendar.class, new JsonSerializer<GregorianCalendar>() {
public JsonElement serialize(GregorianCalendar date, Type type, JsonSerializationContext context) {
return new JsonPrimitive("/Date(" + date.getTimeInMillis() + ")/");
}
}).create();
Ended up doing the following:
When I add my object to the HttpPost request as json
StringEntity, I fix the escaped backslashes:I would still be interested in a “better” way of accomplishing this, if it exists…