java通过rest调用php暴露的接口,同一字段可能为false或List,反序列化报错

来源:互联网 发布:mac os 10.12 iso下载 编辑:程序博客网 时间:2024/06/05 14:08
1.定义类型转换器
/** * POJO属性有值是List,无值是false * * @author dujiayong * @create 2017-11-02 9:37 */public class ImagesFormater extends JsonDeserializer {    @Override    public Object deserialize(JsonParser jp, DeserializationContext context) throws IOException, JsonProcessingException {        Object object = null;        TreeNode treeNode = jp.getCodec().readTree(jp);        ObjectMapper mapper = new ObjectMapper();        String json = mapper.writeValueAsString(treeNode);        if(treeNode instanceof ArrayNode){            object = mapper.readValue(json,List.class);        }        return object;    }}
2.在特定属性上运用类型转换器
/** * 特色能力图片 */@JsonDeserialize(using = ImagesFormater.class)private List<ShopInfoImages> AbilityImages;

参考网址:
- http://blog.csdn.net/is_zhoufeng/article/details/7827221
- http://jackyrong.iteye.com/blog/2005323

阅读全文
0 0
原创粉丝点击