jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

Provide exact field name in MismatchedInputExceptions

Open rrahman-brex opened this issue 2 years ago • 1 comments

Not sure if there is a solution for this but from what I see there is no way to get the exact field name causing a MismatchedInputException at the moment. There is a message on the exception which includes the property name, but it's in a formatted string with other words.

Is there an existing way to get the field name of the field causing the exception, or would it be possible to add that into the exception object somewhere? Otherwise our user sees a long error message like Missing required creator property 'a' (index 1) at [Source: (String)"{}"; line: 1, column: 1] when all we'd like to show them is something like Missing property 'a'.

The property is available here before it's formatted: https://github.com/FasterXML/jackson-databind/blob/2.14/src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java#L1756

Thanks!

rrahman-brex avatar Mar 22 '22 20:03 rrahman-brex

Typically it really depends on where and how the exception is triggered: sometimes information is available, sometimes not. So there is probably not a single fix but a set of improvements.

Pull Requests welcome -- I am always +1 for improved exception messages!

cowtowncoder avatar Mar 23 '22 15:03 cowtowncoder