Skip to content

SPR-14925: Return 5xx HTTP status for invalid target types with Jackson - #1376

Closed
sdeleuze wants to merge 1 commit into
spring-projects:masterfrom
sdeleuze:SPR-14925
Closed

sdeleuze wants to merge 1 commit into
spring-projects:masterfrom
sdeleuze:SPR-14925

Conversation

@sdeleuze

@sdeleuze sdeleuze commented Apr 5, 2017

Copy link
Copy Markdown
Contributor

InvalidDefinitionException has been introduced in Jackson 2.9 to be
able to differentiate invalid data sent from the client (should still
generate a 4xx HTTP status code) from server side errors like beans with
no default constructor (should generate a 5xx HTTP status code).

Could you have a look and say me if you are ok @poutsma ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, Optionals should only be used as a return type, not a field value. So I would store this as a HttpStatus field with a potential null value. See http://blog.joda.org/2014/11/optional-in-java-se-8.html for reasons why.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, fixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should generally remain defensive against overuse of Optional. So agreed, let's avoid it as field type and only expose it for method signatures where it nicely aligns with typical use of the method.

InvalidDefinitionException has been introduced in Jackson 2.9 to be
able to differentiate invalid data sent from the client (should still
generate a 4xx HTTP status code) from server side errors like beans with
no default constructor (should generate a 5xx HTTP status code).

Issue: SPR-14925
@sdeleuze

sdeleuze commented Apr 5, 2017

Copy link
Copy Markdown
Contributor Author

Merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants