Home > Net >  Use @RequestBody to map JSON to a class with @Builder
Use @RequestBody to map JSON to a class with @Builder

Time:12-16

I am using @RequestBody to map JSON body of a POST request to my java class. My POST request was working fine initially, but when I add the @Builder annotation to my java class it started fail. I was wandering how I can use @RequestBody to map JSON to a class with @Builder annotation

My Controller Class

@RequestMapping(value = { "/cards/add" }, method = RequestMethod.POST)
    public void addCard(final HttpServletResponse response, @RequestBody Card request) {
    ...
}

My Model Class

@Data
@Builder
public class Card {

    private String Id;
    ...
}

CodePudding user response:

Try adding these:

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Card {

    private String Id;
    ...
}

  • Related