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

Support additionalProperties from json schema #5

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

Support additionalProperties from json schema #5

joelittlejohn opened this issue Jun 23, 2013 · 5 comments

Comments

@joelittlejohn
Copy link
Owner

Original author: matthew....@gmail.com (December 22, 2010 16:42:22)

In case we don't know in advance what all the properties will be, we would still like to be able to marshall and unmarshall into Java easily.

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

@joelittlejohn
Copy link
Owner Author

From matthew....@gmail.com on December 22, 2010 16:47:27
{"description":"something with additional properties",
"id":"Example",
"properties":{"XXX":{"type":"string"}},
"additionalProperties":true
}

would make

{"XXX":"something",
"another property":"something else"}

valid, and I would expect the Java API to be like:

example.getAdditionalProperty("another property") returns "something else"

or

example.getAdditionalProperties() returns Map<String, Object>

@joelittlejohn
Copy link
Owner Author

From matthew....@gmail.com on December 22, 2010 17:36:57
Actually my first code example would conflict if there was actually a property called "AdditionalProperty" - so don't try that :)

@joelittlejohn
Copy link
Owner Author

From joelittl...@gmail.com on December 22, 2010 19:07:47
Hi Matthew, I've already implemented this one in a local branch. I'm having some strange results when merging back into trunk though - more down to my lack of hg knowledge than any real problem with resolving conflicts.

The details are:

@JsonAnySetter
void setAdditionalProperties(String name, TYPE value) {...}

@JsonAnyGetter
Map<String,TYPE> getAdditionalProperties() {...}

The spec is a little hard to understand but I believe "additionalProperties":true is invalid. The default for additionalProperties is an empty schema (any additional props allowed), if additionalProperties is present it must be either false (no additional props allowed) or a schema (additional props allowed, but values must be valid according to the given schema).

So "additionalProperties":true should actually be written as "additionalProperties":{} or, alternatively, by not specifying the additionalProperties property at all.

@joelittlejohn
Copy link
Owner Author

From joelittl...@gmail.com on December 22, 2010 20:43:36
Tip of the day: feature branches are not a good workflow for Mercurial :D

@joelittlejohn
Copy link
Owner Author

From joelittl...@gmail.com on December 23, 2010 00:06:52
Fixed in 0.1.3

flibbertigibbet added a commit to flibbertigibbet/jsonschema2pojo that referenced this issue Feb 4, 2016
…m-media-type

Use custom type for media fields.
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