java - Json with one required field out of multiple fields -


i have json model requires at least 1 field out of two set. put way, should not allow null fields, , @ same time should not require both fields specified.

is there way accomplish jackson?

the crucial decision make whether constraint describe system/technical one, or 1 specified business logic of application. jackson merely serialization/deserialization library. verifying semantic correctness of serialized data beyond scope.

you can, of course, use custom deserializer verify correctness of input , throw jsonparseexception on invalid input. approach, however, might leave parser in unstable state. therefore should used catch issues related serialization itself, such trying deserialize incompatible version of object, discarding whole input valid solution.

for cases, suggest leaving in-depth validation of user input actual application code. keep serializer , deserializer implementations simple possible - let them remain unchanged when application logic changes.

trying incorporate actual business logic json parser complicate architecture. mix handling of system errors, such serialization of incompatible objects, application errors, such malicious client filling in fields related distinct user groups @ same time.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -