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

Properties should be nullable, use wrapper types not primitives #31

Closed
joelittlejohn opened this issue Jun 23, 2013 · 2 comments
Closed

Comments

@joelittlejohn
Copy link
Owner

Original author: joelittl...@gmail.com (July 06, 2011 23:08:55)

We're currently mapping various schema types to primitive types, which doesn't work well when incoming JSON omits a property altogether. Since Java properties with primitive types are obviously not nullable, we end up with implicit defaults, and no way to distinguish between a value that was omitted and a value that was equal to the primitive default value.

Simple example...

for this schema:
{
"type" : "object",
"properties" : {
"a" : {
"type" : "integer"
}
}
}

we end up with a Java property of type 'int', and hence this data:

{ "a" : 0 }

is indistinguishable from this data:

{}

Clearly this is a significant change to the way POJO generation works (a breaking change in some rare cases where auto-boxing is not enough to keep things happy), hence this is targetted for 0.2.0.

Original issue: http://code.google.com/p/jsonschema2pojo/issues/detail?id=31

@joelittlejohn
Copy link
Owner Author

From joelittl...@gmail.com on September 26, 2011 21:01:00
Fix revisions:

r0c6f57738695,
r4b2d6ba9d83e,
r6c1e42d097a9,
rdf0b5c4f7579

Although the default is now to use wrapper types (and support nullable properties), there's now a new behavioural property 'usePrimitives' (--use-primitives or -P for the CLI) to switch to old behaviour and use primitive types.

@joelittlejohn
Copy link
Owner Author

From joelittl...@gmail.com on September 26, 2011 21:06:08
Implementation notes:

As part of this change, we've moved away from the behavioural properties 'map of strings' and now have a strongly typed config interface:

com.googlecode.jsonschema2pojo.GenerationConfig

Both the maven plugin and CLI argument object implement this interface, which reduces duplication and adds compile time checking when adding new properties.

For the CLI, we've switched from commons-cli to JCommander. CLI arguments are now expressed via annotations on a config object, which makes implementing the GenerationConfig interface easy in the CLI module.

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

No branches or pull requests

1 participant