Skip to content Skip to sidebar Skip to footer

Convert Microsoft Json Date To Java Date

I consume a rest service and i get a json object , and i map json object to my java object with Gson library. But Date Json with following format not deserialized : '/Date(1466606

Solution 1:

finally i use this code for date deserialization :

public class JsonDateDeserializer implements com.google.gson.JsonDeserializer<Date>{

public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {

    String s = json.getAsJsonPrimitive().getAsString();

    String s1 = s.substring(6, s.length() - 2);

    String[] saa = s1.split("\\+");

    long l = Long.parseLong(saa[0]);
    Date d = new Date(l);
    return d;
}
}

Post a Comment for "Convert Microsoft Json Date To Java Date"