{"action":"created","issue":{"url":"https://api.github.com/repos/joelittlejohn/jsonschema2pojo/issues/392","labels_url":"https://api.github.com/repos/joelittlejohn/jsonschema2pojo/issues/392/labels{/name}","comments_url":"https://api.github.com/repos/joelittlejohn/jsonschema2pojo/issues/392/comments","events_url":"https://api.github.com/repos/joelittlejohn/jsonschema2pojo/issues/392/events","html_url":"https://github.com/joelittlejohn/jsonschema2pojo/issues/392","id":96320977,"number":392,"title":"Generating a POJO using oneOf, anyOf or allOf with constraints","user":{"login":"CasperDB","id":8224421,"avatar_url":"https://avatars.githubusercontent.com/u/8224421?v=3","gravatar_id":"","url":"https://api.github.com/users/CasperDB","html_url":"https://github.com/CasperDB","followers_url":"https://api.github.com/users/CasperDB/followers","following_url":"https://api.github.com/users/CasperDB/following{/other_user}","gists_url":"https://api.github.com/users/CasperDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CasperDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CasperDB/subscriptions","organizations_url":"https://api.github.com/users/CasperDB/orgs","repos_url":"https://api.github.com/users/CasperDB/repos","events_url":"https://api.github.com/users/CasperDB/events{/privacy}","received_events_url":"https://api.github.com/users/CasperDB/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/joelittlejohn/jsonschema2pojo/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":21,"created_at":"2015-07-21T13:54:51Z","updated_at":"2015-12-14T18:26:39Z","closed_at":null,"body":"I'm generating a POJO using the jsonschema2pojo-maven-plugin and need to pass constraints in using oneOf, anyOf & allOf.\r\n\r\nWhen I try the following code in a schema validator it works:\r\n```\r\n{\r\n  \"type\": \"object\",\r\n  \"properties\": {\r\n    \"name\": {\r\n      \"description\": \"The advertised product\",\r\n      \"type\": \"string\"\r\n    },\r\n    \"id\" : {\r\n      \"oneOf\": [\r\n        { \"type\": \"string\", \"maxLength\": 5 },\r\n        { \"type\": \"number\", \"minimum\": 0 }\r\n      ]\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nHowever, the POJO after building has no constraints:\r\n```\r\n @JsonProperty(\"id\")\r\n    private Object id;\r\n```\r\n\r\nI would like to see some restrictions annotated, is this not supported with the plugin yet?"},"comment":{"url":"https://api.github.com/repos/joelittlejohn/jsonschema2pojo/issues/comments/164517828","html_url":"https://github.com/joelittlejohn/jsonschema2pojo/issues/392#issuecomment-164517828","issue_url":"https://api.github.com/repos/joelittlejohn/jsonschema2pojo/issues/392","id":164517828,"user":{"login":"ctrimble","id":614753,"avatar_url":"https://avatars.githubusercontent.com/u/614753?v=3","gravatar_id":"","url":"https://api.github.com/users/ctrimble","html_url":"https://github.com/ctrimble","followers_url":"https://api.github.com/users/ctrimble/followers","following_url":"https://api.github.com/users/ctrimble/following{/other_user}","gists_url":"https://api.github.com/users/ctrimble/gists{/gist_id}","starred_url":"https://api.github.com/users/ctrimble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctrimble/subscriptions","organizations_url":"https://api.github.com/users/ctrimble/orgs","repos_url":"https://api.github.com/users/ctrimble/repos","events_url":"https://api.github.com/users/ctrimble/events{/privacy}","received_events_url":"https://api.github.com/users/ctrimble/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T18:26:39Z","updated_at":"2015-12-14T18:26:39Z","body":"As far as computing the types, a wiki page should probably be started.  High level, the needed rules seem something like:\r\n\r\nFor `allOf`:\r\n\r\n1. Property lists are merged.  If properties overlap, then they must be of the same type or one must directly extend the other.\r\n2. The required set of properties would widen, to include any property that is required in any schema.\r\n\r\nFor `anyOf`:\r\n\r\n1. Property lists are merged,  If properties overlap, then the rules for `oneOf` are applied.\r\n2. The required set of properties would narrow, to only include properties that are required in all schemas.\r\n\r\nFor `oneOf`:\r\n\r\n1. The property's type would be the most specific common superclass of the types involved.\r\n2. Tests for being that type are created (perhaps static method on type with `isThisType(JsonTree tree)`).\r\n3. The tests are applied in order, inside a generated JsonDeserializer that is applied to the property containing the `oneOf`.\r\n\r\nThis strategy would only work for Jackson.  I have no clue how GSON deals with types like this.  I guess `Map`, `List`, or the target (de)serializers generic JSON representation could be returned for other tools.\r\n"}}