0

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.

Iraj
  • 1,492
  • 5
  • 18
  • 42
  • Possible duplicate of ["Unparseable date: 1302828677828" trying to deserialize with Gson a millisecond-format date received from server](http://stackoverflow.com/questions/5671373/unparseable-date-1302828677828-trying-to-deserialize-with-gson-a-millisecond) – Mrunal Pagnis Jul 27 '16 at 07:30

1 Answers1

0

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;
}
}
Iraj
  • 1,492
  • 5
  • 18
  • 42