I have a spring boot app where I am planning to write an API which is a GET request but has many request parameters in it. So I have created a POJO which maps the request params to the POJO. I wanted to deserialize it before mapping the request params to POJO.
How can I achieve that?
I have created the custom deserializer and annotated the POJO with @JsonDeserialize(using = "CustomDeserializer.class")
.
Call is not landing to the deserializer but mapping the fields directly to the POJO.
//pojo
@Getter
@Setter
@JsonDeserialize(using = CustomDeserializer.class)
public class GetRequest implements Serializable {
private int id;
private String date;
private List<Test> List;
private int uiRank;
private int fr;
private String city;
private String state;
private String country;
}
//Deserializer
@JsonComponent
public class CustomDeserializer extends JsonDeserializer<GetRequest> {
@Override
public GetRequest deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
//logic to deserialize
}
}
//controller
@RestController
public class TestController {
@GetMapping("/details")
public void getTestDetails(GetRequest getRequest) {
//logic
}
}
Cannot use queryparam annotation on an API in a controller as I have many query params. I need to use a POJO which is mapped with all the query params but before that deserializer needs to be executed.