I have rest service that return arraylist of object,and I have implemented jersy restful client to execute it,but I have problem in converting ZonedDateTime type to json so
Your solution posted doesn't work because ZonedDateTime's Json serialization is not a Json primitive but a Json object that contains more than a single element. It needs to develop a bit and here is a completed solution:
public Gson gson() {
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new JsonDeserializer() {
@Override
public ZonedDateTime deserialize(JsonElement json, Type type,
JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
JsonObject dateTime = jsonObj.getAsJsonObject("dateTime");
JsonObject date = dateTime.getAsJsonObject("date");
int year = date.get("year").getAsInt();
int month = date.get("month").getAsInt();
int day = date.get("day").getAsInt();
JsonObject time = dateTime.getAsJsonObject("time");
int hour = time.get("hour").getAsInt();
int minute = time.get("minute").getAsInt();
int second = time.get("second").getAsInt();
int nano = time.get("nano").getAsInt();
JsonObject zone = jsonObj.getAsJsonObject("zone");
String id = zone.get("id").getAsString();
return ZonedDateTime.of(year, month, day, hour, minute, second, nano, ZoneId.of(id));
}
}).create();
}