ssm框架的一个项目,数据库从mysql向oracle迁移的时候,会出现如下的错误:

WARN  org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON document: No serializer found for class oracle.jdbc.driver.OracleClobReader and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.tkamc.commons.result.PageInfo["rows"]->java.util.ArrayList[0]->java.util.HashMap["ROLESLIST"]->com.alibaba.druid.proxy.jdbc.ClobProxyImpl["characterStream"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class oracle.jdbc.driver.OracleClobReader and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.tkamc.commons.result.PageInfo["rows"]->java.util.ArrayList[0]->java.util.HashMap["ROLESLIST"]->com.alibaba.druid.proxy.jdbc.ClobProxyImpl["characterStream"])


需要把clob字段转换成String类型的,方法如下:

       List<Map<String, Object>> list = userMapper.selectUserPage(page, pageInfo.getCondition());
        //把clob类型的字段转换成String
        for(Map<String, Object> data:list){
            for(String key:data.keySet()){
                if(data.get(key) instanceof Clob){
                    Clob clob  = (Clob) data.get(key);
                    try {
                        data.put(key, clob.getSubString((long)1,(int)clob.length()));
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }