0

could some one explain me why Spring Boot is not able to deserialize this JSON? Based on this online validator, it is valid JSON.

{
    "name": "someName"
}

I am getting this error:

"Cannot construct instance of `com.znamenacek.debtor.dto.GroupDto$Request$Create` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 2, column: 5]"

The class I am trying to serialize/deserialize is following:

@Value @Builder(toBuilder = true) @ToString
        public static class Create{
            @NotBlank(message = "Name must be filled")
            String name;
        }

I have just discovered that it is accepting the value in this format:

"someName"

To me it seems strange ...

Jakub Znamenáček
  • 766
  • 1
  • 4
  • 18
  • That's exactly what jackson `@Value` annotation does. What did you expect? And it's really bad idea to use lombok `@Builder` annotation to your DTO classes – Vasily Liaskovsky Jun 02 '22 at 10:45
  • The @Value is not jackson's annotation, it is from lombok. BTW why it is bad idea to use builder? – Jakub Znamenáček Jun 02 '22 at 10:55
  • Basically, anything that interfers with instantiation is bad idea when dealing with serialize/deserialize libraries such as jackson. You better limit lombok use for this class to just `@Data` - it generates getters/setters which are ok. – Vasily Liaskovsky Jun 02 '22 at 11:00
  • For builders, see this: https://stackoverflow.com/questions/4982340/jackson-builder-pattern. Edit, or this, more targeted: https://stackoverflow.com/questions/66399749/using-jackson-to-deserialize-with-lombok-builder – M. Prokhorov Jun 02 '22 at 11:23

0 Answers0