-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve exception used, message, when indicating a required
property is not set
#2302
Comments
I am not sure what to do here, to be honest. Jackson project does not control Auto-Value (or Immutables, Lombok); and Kotlin data classes are handled by Kotlin module. I agree in that it would be good to surface problem in same or at least similar way, and that exception message should give as much information as possible. But since handling is widely diverging it is necessary to tackle specific problems, I think, starting with what |
I don't know |
@raubel that makes sense from user perspective, but from implementation perspective things are different -- the problem is that figuring out what is missing requires more bookkeeping internally than just matching what exists. And since So implementing support for validation requires much more thought, to ensure that performance is not significantly affected with added tracking (despite size of API Jackson critical path processing is quite lean and additional data structures will be observable in throughput). |
Note: if someone could just provide a test case in which we get "wrong" exception message -- |
required
property is not set
@cowtowncoder , I will take a crack at this. Just to clarify my understanding for time being you simply want a test case of what should happen ie |
@akohli96 Now, on test, I'd be interested in finding case(s) where exception message does not give enough indication of missing required property/-ies; use of Oh, and on commenting: there is separate "..../failing" directory for tests that would fail; these tests are not run with regular "mvn test" but only when directly referenced. So that might actually be the best location. |
Not sure how to proceed here; and while I am +100 on improving error messages, would need more specific information on what is missing, with a test case against Jackson 2.12. May be re-opened or re-filed with more information; closing for now. |
I'm using Jackson 2.9.8.
I want to deserialize a payload to a class with
JsonProperty(required = true)
annotated fields.If the payload does not contain all necessary fields, I want to inform my API user with a concise (possibly custom) message.
However, the Jackson deserialization only gives me an
InvalidDefinitionException
("Cannot construct instance of...") with the root cause, which depends on the underlying technology. For instance, with the AutoValue framework, the root cause is anIllegalStateException
("Missing required properties:...") and with Kotlin data classes, it is anIllegalArgumentException
("Parameter specified as non-null is null").Since all fields are annotated, I guess Jackson could be able to produce something like a
MissingFieldException
(with field name, path...). The same way it is able to produce aUnrecognizedFieldException
when an unknown field is met.The text was updated successfully, but these errors were encountered: