jackson - Jackson使用,String与对象互转

准备

    // jackson转换工具
    private static final ObjectMapper objectMapper = new ObjectMapper()
            .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);

使用

对象转json

String str = objectMapper.writeValueAsString(new MessageEntity());

json转对象

List<String> tidList = objectMapper.readValue(tidListSrt, new TypeReference<List<String>>() {});
posted @ 2018-07-06 19:59  舞羊  阅读(7435)  评论(0编辑  收藏  举报