Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

643
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!