Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
return json array from spring controller

I want to return with my controller spring a JSONARRAY, but when running I receive this error:

java.lang.IllegalArgumentException: No converter found for return value of type: class org.codehaus.jettison.json.JSONArray

this is my code :

@RequestMapping(value = "/generate", method = RequestMethod.GET)
@ResponseBody
public JSONArray generate() throws NoSuchFieldException, CloneNotSupportedException{

        return facturationSvc.facturer();
}

NB:The method "facturer()" of the service "facturationSvc" , returns a JSON ARRAY

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You should return a java List, not a JSONArray. Spring uses Jackson, and the purpose of jackson is to convert java object to/from base elements like JsonArray, and then to a Json String

You don't need to directly manage json, Spring does it all for you, so the solution here is to change your return types (of the controller and the service) and manage only java Objects

@RequestMapping(value = "/generate", method = RequestMethod.GET) 
@ResponseBody public List<YourFacturerClass> generate() {

    return facturationSvc.facturer();

}
about 4 years ago · Santiago Trujillo Relatório

0

you should be returning string not JSONArray,

String generate() throws NoSuchFieldException, CloneNotSupportedException{

      return facturationSvc.facturer().toString();
}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda