I have to validate a JSON payload to check if all the request attributes mentioned on the Rest API Specification are passed. the value of some of these can be null. The use of JSON annotations like @NotNull, @NotEmpty is not suitable as they validate the value as well.
I have tried @Jsoncreator on a constructor. This solution works perfect for simple payloads but I am not clear on how to get this worked in case of complex payloads involving nested objects.
Another problem to highlight is that the same objects are used for both POST and PUT operation payloads. I need the validation for only PUT operations.
Can you please suggest on feasible solutions?
for a JSON request of 2 attributes - name, age -
valid payloads -
{"name" :"StackOverflow", "age" :99}
{"name" :"StackOverflow", "age" :null}
invalid payload - {"name" :"StackOverflow"}