com.fasterxml.j ackson.databind.JsonMappingException:没有为类org.json.JSO找到序列化程序NObject

时间:2017-06-06 16:50:27

标签: java json

我正在进行休息服务,在那里我查询solr并从一天获得结果,直到数据从今天开始,问题是当我尝试构建我的服务响应时JSONArray我收到此警告,并收到来自我服务器的404响应。

堆栈跟踪:

WARN  DefaultHandlerExceptionResolver:400 - Failed to write
HTTP message: org.springframework.http.converter.HttpMessageNotWritableException
: Could not write content: No serializer found for class org.json.JSONObject and
 no properties discovered to create BeanSerializer (to avoid exception, disable
SerializationFeature.FAIL_ON_EMPTY_BEANS) ); nested exception is com.fasterxml.j
ackson.databind.JsonMappingException: No serializer found for class org.json.JSO
NObject and no properties discovered to create BeanSerializer (to avoid exceptio
n, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )

函数的代码:

public Object getHistorico(String field){

        Calendar fechaConsulta= Calendar.getInstance();
        Date inicio,fin,hoy;
        hoy = fechaConsulta.getTime();

        fechaConsulta.set(Calendar.YEAR, 2017);
        fechaConsulta.set(Calendar.MONTH, 0);
        fechaConsulta.set(Calendar.DAY_OF_MONTH, 1);

        JSONArray array = new JSONArray();

        do{

        fechaConsulta.set(Calendar.HOUR_OF_DAY, 0);
        fechaConsulta.set(Calendar.MINUTE, 0);
        fechaConsulta.set(Calendar.SECOND, 0);
        inicio = fechaConsulta.getTime();

        fechaConsulta.set(Calendar.HOUR_OF_DAY, 23);
        fechaConsulta.set(Calendar.MINUTE, 59);
        fechaConsulta.set(Calendar.SECOND, 59);

        fin = fechaConsulta.getTime();

        List<IndicadorDatos> historico = indicadoresDatosRepository.getHistorico(inicio,fin);

        JSONObject json = new JSONObject();

        for(IndicadorDatos h:historico){

            Object obj = h; // The object you want to inspect
            Class<?> clase = obj.getClass();

            Field propiedad;
            try {
                propiedad = clase.getDeclaredField(field);
                propiedad.setAccessible(true);

                Double val = Util.getDouble((Double) propiedad.get(obj));
                json.put(h.getDestino(), val);
            } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }

        json.put("fecha", inicio.toString());
        array.put(json);
        fechaConsulta.add(Calendar.DATE, 1);


        }while(fin.after(hoy));

         return array;  

    }
来自pom的

json版本:

<dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20170516</version>
        </dependency>
来自其他服务的

@RequestMapping(value = "/getHistorico", method = RequestMethod.GET, produces = { "application/json" })
    public Object getHistorico(@RequestParam(value = "field") String field) {


        return serviceCalculoPromedioIndicadores.getHistorico(field);
    }

我不确定为什么我会收到此错误。为什么我错过了?

0 个答案:

没有答案