Open irislove opened 9 years ago
Hi,
I'm using your web tool to generate POJOs from JSON schema file. However it doesn't generate POJOs for any object types that are in an array.
For example, the following JSON schema generates POJOs with a list of generic type Object in class Example.java "private List should = new ArrayList()":
JSON schema:
{ "$schema": "http://json-schema.org/draft-04/schema#", "id": "/", "type": "object", "properties": { "should": { "id": "should", "type": "array", "items": [ { "id": "0", "type": "object", "properties": { "match": { "id": "match", "type": "object", "properties": { "name": { "id": "name", "type": "object", "properties": { "query": { "id": "query", "type": "string" }, "boost": { "id": "boost", "type": "integer" } } } } } } }, { "id": "1", "type": "object", "properties": { "multi_match": { "id": "multi_match", "type": "object", "properties": { "fields": { "id": "fields", "type": "array", "items": [ { "id": "0", "type": "string" }, { "id": "1", "type": "string" } ] }, "query": { "id": "query", "type": "string" }, "boost": { "id": "boost", "type": "integer" } } } } }, { "id": "2", "type": "object", "properties": { "match": { "id": "match", "type": "object", "properties": { "meta.themes": { "id": "meta.themes", "type": "object", "properties": { "query": { "id": "query", "type": "string" }, "boost": { "id": "boost", "type": "integer" } } } } } } }, { "id": "3", "type": "object", "properties": { "match_phrase_prefix": { "id": "match_phrase_prefix", "type": "object", "properties": { "more_info": { "id": "more_info", "type": "object", "properties": { "query": { "id": "query", "type": "string" }, "boost": { "id": "boost", "type": "integer" }, "max_expansions": { "id": "max_expansions", "type": "integer" } } } } } } } ] } } }
Generated POJOs: NOTE: private List should = new ArrayList(); in Example.java
-----------------------------------com.example.Example.java----------------------------------- package com.example; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Generated; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "should" }) public class Example { @JsonProperty("should") private List<Object> should = new ArrayList<Object>(); @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<String, Object>(); /** * * @return * The should */ @JsonProperty("should") public List<Object> getShould() { return should; } /** * * @param should * The should */ @JsonProperty("should") public void setShould(List<Object> should) { this.should = should; } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } }
If I generate POJOs from the actual JSON example, it seems to generates the POJOs as I expected:
JSON example:
{ "should": [ { "match": { "name": { "query": "", "boost": 3 } } }, { "multi_match": { "fields": [ "description", "more_info" ], "query": "", "boost": 2 } }, { "match": { "meta.themes": { "query": "", "boost": 2 } } }, { "match_phrase_prefix": { "more_info": { "query": "", "boost": 1, "max_expansions": 50 } } } ] }
-----------------------------------com.example.Example.java----------------------------------- package com.example; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Generated; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "should" }) public class Example { @JsonProperty("should") private List<Should> should = new ArrayList<Should>(); @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<String, Object>(); /** * * @return * The should */ @JsonProperty("should") public List<Should> getShould() { return should; } /** * * @param should * The should */ @JsonProperty("should") public void setShould(List<Should> should) { this.should = should; } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } -----------------------------------com.example.Match.java----------------------------------- package com.example; import java.util.HashMap; import java.util.Map; import javax.annotation.Generated; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "meta.themes" }) public class Match { @JsonProperty("meta.themes") private MetaThemes metaThemes; @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<String, Object>(); /** * * @return * The metaThemes */ @JsonProperty("meta.themes") public MetaThemes getMetaThemes() { return metaThemes; } /** * * @param metaThemes * The meta.themes */ @JsonProperty("meta.themes") public void setMetaThemes(MetaThemes metaThemes) { this.metaThemes = metaThemes; } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } -----------------------------------com.example.MatchPhrasePrefix.java----------------------------------- package com.example; import java.util.HashMap; import java.util.Map; import javax.annotation.Generated; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "more_info" }) public class MatchPhrasePrefix { @JsonProperty("more_info") private MoreInfo moreInfo; @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<String, Object>(); /** * * @return * The moreInfo */ @JsonProperty("more_info") public MoreInfo getMoreInfo() { return moreInfo; } /** * * @param moreInfo * The more_info */ @JsonProperty("more_info") public void setMoreInfo(MoreInfo moreInfo) { this.moreInfo = moreInfo; } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } -----------------------------------com.example.MetaThemes.java----------------------------------- package com.example; import java.util.HashMap; import java.util.Map; import javax.annotation.Generated; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "query", "boost" }) public class MetaThemes { @JsonProperty("query") private String query; @JsonProperty("boost") private Integer boost; @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<String, Object>(); /** * * @return * The query */ @JsonProperty("query") public String getQuery() { return query; } /** * * @param query * The query */ @JsonProperty("query") public void setQuery(String query) { this.query = query; } /** * * @return * The boost */ @JsonProperty("boost") public Integer getBoost() { return boost; } /** * * @param boost * The boost */ @JsonProperty("boost") public void setBoost(Integer boost) { this.boost = boost; } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } -----------------------------------com.example.MoreInfo.java----------------------------------- package com.example; import java.util.HashMap; import java.util.Map; import javax.annotation.Generated; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "query", "boost", "max_expansions" }) public class MoreInfo { @JsonProperty("query") private String query; @JsonProperty("boost") private Integer boost; @JsonProperty("max_expansions") private Integer maxExpansions; @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<String, Object>(); /** * * @return * The query */ @JsonProperty("query") public String getQuery() { return query; } /** * * @param query * The query */ @JsonProperty("query") public void setQuery(String query) { this.query = query; } /** * * @return * The boost */ @JsonProperty("boost") public Integer getBoost() { return boost; } /** * * @param boost * The boost */ @JsonProperty("boost") public void setBoost(Integer boost) { this.boost = boost; } /** * * @return * The maxExpansions */ @JsonProperty("max_expansions") public Integer getMaxExpansions() { return maxExpansions; } /** * * @param maxExpansions * The max_expansions */ @JsonProperty("max_expansions") public void setMaxExpansions(Integer maxExpansions) { this.maxExpansions = maxExpansions; } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } -----------------------------------com.example.MultiMatch.java----------------------------------- package com.example; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Generated; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "fields", "query", "boost" }) public class MultiMatch { @JsonProperty("fields") private List<String> fields = new ArrayList<String>(); @JsonProperty("query") private String query; @JsonProperty("boost") private Integer boost; @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<String, Object>(); /** * * @return * The fields */ @JsonProperty("fields") public List<String> getFields() { return fields; } /** * * @param fields * The fields */ @JsonProperty("fields") public void setFields(List<String> fields) { this.fields = fields; } /** * * @return * The query */ @JsonProperty("query") public String getQuery() { return query; } /** * * @param query * The query */ @JsonProperty("query") public void setQuery(String query) { this.query = query; } /** * * @return * The boost */ @JsonProperty("boost") public Integer getBoost() { return boost; } /** * * @param boost * The boost */ @JsonProperty("boost") public void setBoost(Integer boost) { this.boost = boost; } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } -----------------------------------com.example.Should.java----------------------------------- package com.example; import java.util.HashMap; import java.util.Map; import javax.annotation.Generated; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "match", "multi_match", "match_phrase_prefix" }) public class Should { @JsonProperty("match") private Match match; @JsonProperty("multi_match") private MultiMatch multiMatch; @JsonProperty("match_phrase_prefix") private MatchPhrasePrefix matchPhrasePrefix; @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<String, Object>(); /** * * @return * The match */ @JsonProperty("match") public Match getMatch() { return match; } /** * * @param match * The match */ @JsonProperty("match") public void setMatch(Match match) { this.match = match; } /** * * @return * The multiMatch */ @JsonProperty("multi_match") public MultiMatch getMultiMatch() { return multiMatch; } /** * * @param multiMatch * The multi_match */ @JsonProperty("multi_match") public void setMultiMatch(MultiMatch multiMatch) { this.multiMatch = multiMatch; } /** * * @return * The matchPhrasePrefix */ @JsonProperty("match_phrase_prefix") public MatchPhrasePrefix getMatchPhrasePrefix() { return matchPhrasePrefix; } /** * * @param matchPhrasePrefix * The match_phrase_prefix */ @JsonProperty("match_phrase_prefix") public void setMatchPhrasePrefix(MatchPhrasePrefix matchPhrasePrefix) { this.matchPhrasePrefix = matchPhrasePrefix; } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } }
Many Thanks,
Iris
I am also facing the same issue, appreciate if it's been taken on priority
Hi,
I'm using your web tool to generate POJOs from JSON schema file. However it doesn't generate POJOs for any object types that are in an array.
For example, the following JSON schema generates POJOs with a list of generic type Object in class Example.java "private List
JSON schema:
Generated POJOs: NOTE: private List should = new ArrayList(); in Example.java
If I generate POJOs from the actual JSON example, it seems to generates the POJOs as I expected:
JSON example:
Generated POJOs: NOTE: private List should = new ArrayList(); in Example.java
Many Thanks,
Iris