Skip to content
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

Fallback to simple String for invalid JSON body #39

Merged
merged 2 commits into from
Dec 19, 2015

Conversation

lukasniemeier-zalando
Copy link
Member

Fixes #38

addUnless(builder, "body", request.getBodyAsString(), String::isEmpty);
try {
builder.put("body", body.isEmpty() ? JsonBody.EMPTY : new JsonBody(compactJson(body)));
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Control flow is a bit confusing. Can we maybe extract a method returning an optional or nullable JsonBody?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes - actually, why do we differ in behavior for empty JSON-body and empty non-JSON-body @whiskeysierra ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes - actually, why do we differ in behavior for empty JSON-body and empty non-JSON-body @whiskeysierra ?

I think we can switch those conditions and

  1. check for empty body
  2. check for content type json

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried this but then some tests were failing (those that are checking that for JSON an empty body is serialized as an empty string and for all other content-type the body is omitted). I'd go with omitting the body for an empty body, regardless of the content-type.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I tried this but then some tests were failing (those that are checking that for JSON an empty body is serialized as an empty string and for all other content-type the body is omitted). I'd go with omitting the body for an empty body, regardless of the content-type.

I think I remember now. Depending on which RFC one tries to honor, a json body can be an empty json string, i.e. "", which would be different from an empty body.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Control flow is a bit confusing. Can we maybe extract a method returning an optional or nullable JsonBody?

Would it make sense to use some kind of SPI here to allow embedding bodies as json for different content types? Because with the current approach one always needs to change the JsonHttpLogFormatter.

@lukasniemeier-zalando
Copy link
Member Author

As this is a kind-of breaking bug in this library, should we merge this? We could open an issue to implement the SPI later.

@whiskeysierra
Copy link
Collaborator

As this is a kind-of breaking bug in this library, should we merge this? We could open an issue to implement the SPI later.

Agreed. I created #41

whiskeysierra added a commit that referenced this pull request Dec 19, 2015
Fallback to simple String for invalid JSON body
@whiskeysierra whiskeysierra merged commit e24a817 into zalando:master Dec 19, 2015
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