Jackson InvalidFormatException: Cannot deserialize value of type `java.util.UUID` from String

11,883

Never mind, I searched around and was able to resolve the issue. Below is the solution.

So basically the solution was to remove the ID from the JSON that I was using for the request body. The Json that I was using earlier had dstId as the first key, removing it resolved my error.

{
 "dstId":"4be4bd08cfdf407484f6a04131790949",
  ...
}

Also I realized that the root cause was that the data I was using above is not a valid UUID. Using a valid UUID in it's place worked, for example "dstId": "110841e3-e6fb-4191-8fd8-5674a5107c33

The post that helped me to figure out Spring Boot JSON parse error: Cannot deserialize error

Share:
11,883
VC2019
Author by

VC2019

Updated on June 04, 2022

Comments

  • VC2019
    VC2019 almost 2 years

    Am using Spring boot with a Rest Controller. I have a @PostMapping with a @RequestBody having object that has id of type UUID. When I am trying to test my post request from Postman I get the following error.

    JSON parse error:

    Cannot deserialize value of type java.util.UUID from String "4be4bd08cfdf407484f6a04131790949": UUID has to be represented by standard 36-char representation; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.util.UUID from String "4be4bd08cfdf407484f6a04131790949": UUID has to be represented by standard 36-char representation

    I read in some post that talked about invalidFormatException but with a different data type that need to write some kind of Adapter. How can I resolve this for the UUID? Thanks in advance for your input.

    @PostMapping(value = "/save_order")
    @ResponseStatus(HttpStatus.CREATED)
    public void postOrder(@RequestBody Order order) {
    ...
    
    public class Order {
    @Id
    private UUID dstId;
    ....