-
Notifications
You must be signed in to change notification settings - Fork 85
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
Conversation
@fehguy anything preventing a merge here? |
i will try to review over next couple days |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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" + |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finally, here.
@fehguy |
Looks great, thanks! |
Instead of treating everyting under the first level in an example as a
StringExample
.This will also fix so that
42
will become42
instead of"42"
.I have added
NullExample
andBigIntegerExample
for representingnull
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 totrue
(previously"true"
). This is because YAML treats it as a boolean.1180591620717411303424.42
would become aDecimalExample
(which stores aBigDecimal
but it ends up being transformed to adecimal
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.