问题
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(1466606168687+0430)/"
I also checked following gson object ,but json date is not deserialized yet:
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssz").create();
Update: My problem is time zon for deserializing json date with timezon.
回答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;
}
}
来源:https://stackoverflow.com/questions/38567128/convert-microsoft-json-date-to-java-date