question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve exception used, message, when indicating a `required` property is not set

See original GitHub issue

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 an IllegalStateException (“Missing required properties:…”) and with Kotlin data classes, it is an IllegalArgumentException (“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 a UnrecognizedFieldException when an unknown field is met.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
raubelcommented, Apr 17, 2019

I don’t know jackson-databind enough, but my naive thought was that, since it can report any unexpected property (base on @JsonProperty annotations), it could also report any missing property. We often have objects with a lot of properties, so instead of using the constructor pattern, with the @JsonCreator annotation, we rather use the builder pattern provided by AutoValue (with @JsonProperty annotations).

0reactions
cowtowncodercommented, Dec 4, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot - Detect and terminate if property not set?
To throw a friendly exceptions just put a default null value in property, check and throw a exception in afterProperty method.
Read more >
Exception.Message Property (System) - Microsoft Learn
The Message property is overridden in classes that require control over message content or format. Application code typically accesses this property when it ......
Read more >
Appendix A: SQL Exception and Warning Messages
The following table lists the SQL exception and warning messages that you may ... If you do not need metadata, set the USE_METADATA...
Read more >
WMQ JMS Exception Messages - IBM
Error Code Message Explanation AMS1047 Alias not found in the keystore An alias is not found in the keystore. AMS1051 Failed to initialize the keystore...
Read more >
Exception Error Codes and Descriptions - Oracle Help Center
The mapping is set to use indirection, but the related attribute is not defined as type ValueHolderInterface . It is thrown on foreign...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found