其他分享
首页 > 其他分享> > 用Gson 实体类转换ZonedDateTime类型

用Gson 实体类转换ZonedDateTime类型

作者:互联网

实体类直接转换会报错,所以需要特别转换:

Gson gson=new GsonBuilder().registerTypeAdapter(ZonedDateTime.class,new JsonDeserializer<ZonedDateTime>(){
	@Override
    public ZonedDateTime deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
								return ZonedDateTime.parse(jsonElement.getAsJsonPrimitive().getAsString());
							}
 						}).create();
					return gson.fromJson(result,OrderDigestInfoResp.class);

标签:实体类,return,jsonElement,gson,new,ZonedDateTime,Gson
来源: https://blog.csdn.net/weixin_42246822/article/details/115437740