mybatis查询结果转为string时,若包含null,会报错误

 

    /**  null替换为空字符串 ""  */
    ObjectMapper mapper = new ObjectMapper();  
        mapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {  
            @Override  
            public void serialize(Object arg0, JsonGenerator arg1, SerializerProvider arg2)
                    throws IOException, JsonProcessingException {  
                arg1.writeString("");  
            }  
        });
    try {
        //将包含null值的mybatis查询结果result 中的 null 转为 ""
        String resultString = mapper.writeValueAsString(result);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
                    

 

posted @ 2018-03-06 17:04  留下来  阅读(807)  评论(0编辑  收藏  举报