1

I'm working on a rest service where i make a query to solr and get the results from one day until is the data is from today, the problem is when i try to construct my response for the service in a JSONArray i get this warning, and a 404 response from my server.

Stacktrace:

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) )

the code of the function:

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;  

    }

version of json from pom:

<dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20170516</version>
        </dependency>

from the rest service:

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


        return serviceCalculoPromedioIndicadores.getHistorico(field);
    }

I'm not sure why i'm getting this error. why did i missed?

Progs
  • 1,059
  • 7
  • 27
  • 63
  • Possible duplicate of [Serializing with Jackson (JSON) - getting "No serializer found"?](https://stackoverflow.com/questions/8367312/serializing-with-jackson-json-getting-no-serializer-found) – SilverNak Jun 06 '17 at 16:52
  • Do you try type the return value to JsonArray? – German Jun 06 '17 at 16:52

0 Answers0