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

645
Visualizações
Spring Boot PostMapping deserialize Long array

I'm trying to deserialize a list of Long values:

{
    "ids": [1, 2, 3]
}

With the following Method:

    @PostMapping(value = "/export")
    public ResponseEntity<SomeDto> exportCsv(@RequestBody Long[] ids) {
        // Some methods
        return ResponseEntity.ok(someDto);
    }

But I keep getting the following error: JSON parse error: Cannot deserialize value of type Long. The Error is the same using List<Long>, just for ArrayList<Long>.

I've tried it with @JsonDeserialize(using = NumberDeserializers.LongDeserializer.class), but it seems either it doesn't work or I'm using it wrong.

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

0

The request body above represents a POJO class with ids as a property like below

public class Body {

  private Long[] ids;
  //getters and setters

 }

And then use this POJO as RequestBody

public ResponseEntity<SomeDto> exportCsv(@RequestBody Body body)
over 4 years ago · Santiago Trujillo Relatório

0

With json object you try to send, spring assume it's an object with a member field ids. If you want to attach directly to a list send the following json as body:

[5, 6, 8]

This will work for:

@PostMapping(value = "/export")
public ResponseEntity<SomeDto> exportCsv(@RequestBody Long[] ids) {
...
}

and

@PostMapping(value = "/export")
public ResponseEntity<SomeDto> exportCsv(@RequestBody List<Long> ids) {
...
}
over 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