'JsonUnwrapped to deserialize GET request parameters

I have the following:

@RestController
public class MyController {

    @PostMapping
    MyDto test(@RequestBody MyDto myDto) {
        return myDto;
    }

    @GetMapping
    MyDto test2(MyDto myDto) {
        return myDto;
    }

    @Data
    static class MyDto {
        private String a;
        @JsonUnwrapped
        private MySecondDto secondDto;

        @Data
        static class MySecondDto {
            private String b;
        }
    }
}

However:

GET http://localhost:8080?a=a&b=b

returns

{
    "a": "a"
}

while

POST http://localhost:8080

{
    "a": "a",
    "b": "b"
}

returns

{
    "a": "a",
    "b": "b"
}

so it looks like @JsonUnwrapped and GET mapped Pojos don't work together as expexted. Any hint on how to use complex nested Pojos to accomodate GET request params ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source