Converting ZonedDateTime type to Gson

后端 未结 4 1901
梦谈多话
梦谈多话 2021-01-18 10:33

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

4条回答
  •  一向
    一向 (楼主)
    2021-01-18 10:36

    public static final Gson GSON = new GsonBuilder()
        .registerTypeAdapter(ZonedDateTime.class, new TypeAdapter() {
            @Override
            public void write(JsonWriter out, ZonedDateTime value) throws IOException {
                out.value(value.toString());
            }
    
            @Override
            public ZonedDateTime read(JsonReader in) throws IOException {
                return ZonedDateTime.parse(in.nextString());
            }
        })
        .enableComplexMapKeySerialization()
        .create();
    

提交回复
热议问题