How to invoke default deserialize with gson

前端 未结 4 1695
隐瞒了意图╮
隐瞒了意图╮ 2020-12-25 11:57

I get a json that has \"field\" field.
If the \"field\" has data, then there is an OBJECT that has many (about 20) other fields that are also objects. I can deserialize

4条回答
  •  误落风尘
    2020-12-25 12:13

    public class ExtrasAdapter implements JsonDeserializer {
    @Override
    public Extras deserialize(JsonElement json, Type typeOf, 
                  JsonDeserializationContext context) throws JsonParseException {
        try {
            JsonObject jsonObject = json.getAsJsonObject();
            return new Gson().fromJson(jsonObject , Extras.class); // default deserialization
    
        } catch (IllegalStateException e) {
            return null;
        }
    }
    

提交回复
热议问题