Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

644
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda