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

Handle different types and nested structures when deserializing an example. #183

Merged
merged 3 commits into from
Jan 24, 2017

Conversation

joeljons
Copy link
Contributor

Instead of treating everyting under the first level in an example as a StringExample.
This will also fix so that 42 will become 42 instead of "42".
I have added NullExample and BigIntegerExample for representing null without "null" and big integers.

I ran into some interesting problems when I wanted to write a test for all cases.

  • yes will be transformed to true (previously "true"). This is because YAML treats it as a boolean.
  • I was hoping 1180591620717411303424.42 would become a DecimalExample (which stores a BigDecimal but it ends up being transformed to a decimal already in the first YAML step.

If any of those are something that should be changed I suggest creating new issues.

This PR contains a commit from #182 in order to avoid the merge problems that would come when merging it. Please handle that one first.

@olensmar
Copy link
Contributor

@fehguy anything preventing a merge here?

@fehguy
Copy link
Contributor

fehguy commented Jan 23, 2017

i will try to review over next couple days

Copy link
Contributor

@fehguy fehguy left a comment

Choose a reason for hiding this comment

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

Looks good but the null example should be removed.

import io.swagger.inflector.processors.JsonExampleDeserializer;

@JsonDeserialize(using = JsonExampleDeserializer.class)
public class NullExample extends AbstractExample {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since null is not supported in the spec, I suggest removing this one

return new DecimalExample(node.decimalValue());
} else if (node instanceof LongNode) {
return new LongExample(node.longValue());
} else if (node instanceof NullNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As with above, no support for null

@@ -150,6 +160,12 @@ public void writeValue(JsonGenerator jgen, String field, Example o) throws IOExc
} else {
jgen.writeString(obj.getValue());
}
} else if (o instanceof NullExample) {
Copy link
Contributor

Choose a reason for hiding this comment

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

... and here

" \"int\" : 42,\n" +
" \"biginteger\" : 118059162071741130342442,\n" +
" \"long\" : 1099511627776,\n" +
" \"null-key\" : null,\n" +
Copy link
Contributor

Choose a reason for hiding this comment

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

and here...

int: 42
biginteger: 118059162071741130342442
long: 1099511627776
null-key: null
Copy link
Contributor

Choose a reason for hiding this comment

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

finally, here.

@joeljons
Copy link
Contributor Author

@fehguy
Good point. I didn't know about that. The null example is now removed.

@fehguy
Copy link
Contributor

fehguy commented Jan 24, 2017

Looks great, thanks!

@fehguy fehguy merged commit 1da4579 into swagger-api:master Jan 24, 2017
@fehguy fehguy modified the milestone: v1.0.11 Feb 6, 2017
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