GSON ignore elements with wrong type

后端 未结 5 1000
陌清茗
陌清茗 2020-12-08 11:22

I\'m using Retrofit (in combination with OkHttp and GSON) to communicate with an online webservice. The webservice has a default wrapper around all it\'s responses, similar

5条回答
  •  盖世英雄少女心
    2020-12-08 12:00

    You can use this code as well:

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    yourObject = objectMapper.readValue(jsonString, .class);
    

提交回复
热议问题