jsonb-api
jsonb-api copied to clipboard
Standard Exception for Non-Deserializable
Currently the method deserialize
does not define what shall happen in case a deserializer expects some particular JSON, but does actually find different JSON. This opens way for several outcomes:
-
return null
-
return defaultObject
-
throw RuntimeException
-
throw <TO-BE-DEFINED-STANDARD-EXCEPTION>
In the current situation it is hard for application developers to use deserializers as he has to know what particular solution each particular deserializer chooses. So the outcome is not predictable nor similar.
From the view of an application developer it would be good if a general rule would be defined by JSON-B an application programmer can rely on, and a custom deserializer vendor can follow. My persion but unbias proposal would be to defined a standard exception for that case.
for the TBD standard exception, I think the existing JsonbException
would suffice.
In general, it can vary based on the deserializer developer what the outcome should be for an invalid JSON (null, default object, exception, etc). If developers are registering third-party deserializers (which is rather uncommon in my experience) expected return values can be documented in the javadoc of the deserializer yes?