diff --git a/jsonschema2pojo-core/pom.xml b/jsonschema2pojo-core/pom.xml
index 9086e60ec..0ef4c7cd4 100644
--- a/jsonschema2pojo-core/pom.xml
+++ b/jsonschema2pojo-core/pom.xml
@@ -22,6 +22,10 @@
com.fasterxml.jackson.core
jackson-databind
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-yaml
+
org.scala-lang
scala-library
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ContentResolver.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ContentResolver.java
index ea12b7afb..95a05a910 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ContentResolver.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ContentResolver.java
@@ -26,6 +26,7 @@
import java.util.HashSet;
import java.util.Set;
+import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -38,9 +39,18 @@
public class ContentResolver {
private static final Set CLASSPATH_SCHEMES = new HashSet(asList("classpath", "resource", "java"));
- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
- .enable(JsonParser.Feature.ALLOW_COMMENTS)
- .enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
+
+ private final ObjectMapper objectMapper;
+
+ public ContentResolver() {
+ this(null);
+ }
+
+ public ContentResolver(JsonFactory jsonFactory) {
+ this.objectMapper = new ObjectMapper(jsonFactory)
+ .enable(JsonParser.Feature.ALLOW_COMMENTS)
+ .enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
+ }
/**
* Resolve a given URI to read its contents and parse the result as JSON.
@@ -64,7 +74,7 @@ public JsonNode resolve(URI uri) {
}
try {
- return OBJECT_MAPPER.readTree(uri.toURL());
+ return objectMapper.readTree(uri.toURL());
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Error parsing document: " + uri, e);
} catch (MalformedURLException e) {
@@ -85,7 +95,7 @@ private JsonNode resolveFromClasspath(URI uri) {
}
try {
- return OBJECT_MAPPER.readTree(contentAsStream);
+ return objectMapper.readTree(contentAsStream);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Error parsing document: " + uri, e);
} catch (MalformedURLException e) {
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java
index 9a10aa194..a154e8f58 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java
@@ -35,6 +35,7 @@
import org.jsonschema2pojo.util.NameHelper;
import org.jsonschema2pojo.util.URLUtil;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.sun.codemodel.CodeWriter;
import com.sun.codemodel.JCodeModel;
@@ -57,8 +58,9 @@ public static void generate(GenerationConfig config) throws IOException {
ruleFactory.setAnnotator(annotator);
ruleFactory.setGenerationConfig(config);
+ ruleFactory.setSchemaStore(new SchemaStore(createContentResolver(config)));
- SchemaMapper mapper = new SchemaMapper(ruleFactory, new SchemaGenerator());
+ SchemaMapper mapper = new SchemaMapper(ruleFactory, createSchemaGenerator(config));
JCodeModel codeModel = new JCodeModel();
@@ -90,6 +92,22 @@ public static void generate(GenerationConfig config) throws IOException {
throw new GenerationException("Could not create or access target directory " + config.getTargetDirectory().getAbsolutePath());
}
}
+
+ private static ContentResolver createContentResolver(GenerationConfig config) {
+ if (config.getSourceType() == SourceType.YAMLSCHEMA || config.getSourceType() == SourceType.YAML) {
+ return new ContentResolver(new YAMLFactory());
+ } else {
+ return new ContentResolver();
+ }
+ }
+
+ private static SchemaGenerator createSchemaGenerator(GenerationConfig config) {
+ if (config.getSourceType() == SourceType.YAMLSCHEMA || config.getSourceType() == SourceType.YAML) {
+ return new SchemaGenerator(new YAMLFactory());
+ } else {
+ return new SchemaGenerator();
+ }
+ }
private static RuleFactory createRuleFactory(GenerationConfig config) {
Class extends RuleFactory> clazz = config.getCustomRuleFactory();
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaGenerator.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaGenerator.java
index dd66629be..6c4ac767e 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaGenerator.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaGenerator.java
@@ -22,6 +22,7 @@
import org.jsonschema2pojo.exception.GenerationException;
+import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -39,14 +40,22 @@
public class SchemaGenerator {
- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
- .enable(JsonParser.Feature.ALLOW_COMMENTS)
- .enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
+ private final ObjectMapper objectMapper;
+ public SchemaGenerator() {
+ this(null);
+ }
+
+ public SchemaGenerator(JsonFactory jsonFactory) {
+ this.objectMapper = new ObjectMapper(jsonFactory)
+ .enable(JsonParser.Feature.ALLOW_COMMENTS)
+ .enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
+ }
+
public ObjectNode schemaFromExample(URL example) {
try {
- JsonNode content = OBJECT_MAPPER.readTree(example);
+ JsonNode content = this.objectMapper.readTree(example);
return schemaFromExample(content);
} catch (IOException e) {
throw new GenerationException("Could not process JSON in source file", e);
@@ -68,10 +77,10 @@ public ObjectNode schemaFromExample(JsonNode example) {
private ObjectNode objectSchema(JsonNode exampleObject) {
- ObjectNode schema = OBJECT_MAPPER.createObjectNode();
+ ObjectNode schema = this.objectMapper.createObjectNode();
schema.put("type", "object");
- ObjectNode properties = OBJECT_MAPPER.createObjectNode();
+ ObjectNode properties = this.objectMapper.createObjectNode();
for (Iterator iter = exampleObject.fieldNames(); iter.hasNext();) {
String property = iter.next();
properties.set(property, schemaFromExample(exampleObject.get(property)));
@@ -82,7 +91,7 @@ private ObjectNode objectSchema(JsonNode exampleObject) {
}
private ObjectNode arraySchema(JsonNode exampleArray) {
- ObjectNode schema = OBJECT_MAPPER.createObjectNode();
+ ObjectNode schema = this.objectMapper.createObjectNode();
schema.put("type", "array");
@@ -98,7 +107,7 @@ private ObjectNode arraySchema(JsonNode exampleArray) {
private JsonNode mergeArrayItems(JsonNode exampleArray) {
- ObjectNode mergedItems = OBJECT_MAPPER.createObjectNode();
+ ObjectNode mergedItems = this.objectMapper.createObjectNode();
for (JsonNode item : exampleArray) {
if (item.isObject()) {
@@ -143,11 +152,11 @@ private ObjectNode simpleTypeSchema(JsonNode exampleValue) {
try {
- Object valueAsJavaType = OBJECT_MAPPER.treeToValue(exampleValue, Object.class);
+ Object valueAsJavaType = this.objectMapper.treeToValue(exampleValue, Object.class);
SchemaAware valueSerializer = getValueSerializer(valueAsJavaType);
- return (ObjectNode) valueSerializer.getSchema(OBJECT_MAPPER.getSerializerProvider(), null);
+ return (ObjectNode) valueSerializer.getSchema(this.objectMapper.getSerializerProvider(), null);
} catch (JsonMappingException e) {
throw new GenerationException("Unable to generate a schema for this json example: " + exampleValue, e);
} catch (JsonProcessingException e) {
@@ -158,7 +167,7 @@ private ObjectNode simpleTypeSchema(JsonNode exampleValue) {
private SchemaAware getValueSerializer(Object valueAsJavaType) throws JsonMappingException {
- SerializerProvider serializerProvider = new DefaultSerializerProvider.Impl().createInstance(OBJECT_MAPPER.getSerializationConfig(), BeanSerializerFactory.instance);
+ SerializerProvider serializerProvider = new DefaultSerializerProvider.Impl().createInstance(this.objectMapper.getSerializationConfig(), BeanSerializerFactory.instance);
if (valueAsJavaType == null) {
return NullSerializer.instance;
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaMapper.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaMapper.java
index 8aecd5fe5..151063f83 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaMapper.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaMapper.java
@@ -97,10 +97,12 @@ private ObjectNode readSchema(URL schemaUrl) {
switch (ruleFactory.getGenerationConfig().getSourceType()) {
case JSONSCHEMA:
+ case YAMLSCHEMA:
ObjectNode schemaNode = NODE_FACTORY.objectNode();
schemaNode.put("$ref", schemaUrl.toString());
return schemaNode;
case JSON:
+ case YAML:
return schemaGenerator.schemaFromExample(schemaUrl);
default:
throw new IllegalArgumentException("Unrecognised source type: " + ruleFactory.getGenerationConfig().getSourceType());
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaStore.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaStore.java
index 69eb5cdd8..5a9fd83a3 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaStore.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SchemaStore.java
@@ -27,12 +27,20 @@
public class SchemaStore {
- protected Map schemas = new HashMap();
+ protected final Map schemas = new HashMap();
- protected FragmentResolver fragmentResolver = new FragmentResolver();
- protected ContentResolver contentResolver = new ContentResolver();
+ protected final FragmentResolver fragmentResolver = new FragmentResolver();
+ protected final ContentResolver contentResolver;
- /**
+ public SchemaStore() {
+ this.contentResolver = new ContentResolver();
+ }
+
+ public SchemaStore(ContentResolver contentResolver) {
+ this.contentResolver = contentResolver;
+ }
+
+ /**
* Create or look up a new schema which has the given ID and read the
* contents of the given ID as a URL. If a schema with the given ID is
* already known, then a reference to the original schema will be returned.
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SourceType.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SourceType.java
index 10e5d5d60..7a160624d 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SourceType.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/SourceType.java
@@ -32,5 +32,16 @@ public enum SourceType {
* JSON documents, that represent an example of the kind of JSON data that
* the generated Java types will be mapped to.
*/
- JSON
+ JSON,
+
+ /**
+ * JSON-schema documents, represented as YAML
+ */
+ YAMLSCHEMA,
+
+ /**
+ * YAML documents, that represent an example of the kind of YAML (or JSON) data that
+ * the generated Java types will be mapped to.
+ */
+ YAML
}
diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/json/JsonTypesIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/json/JsonTypesIT.java
index 3fd29c488..296fead83 100644
--- a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/json/JsonTypesIT.java
+++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/json/JsonTypesIT.java
@@ -193,7 +193,7 @@ public void arrayItemsAreNotRecursivelyMerged() throws Exception {
assertEquals(Integer.class, genType.getMethod("getScalar").getReturnType());
thrown.expect(InvalidFormatException.class);
- thrown.expectMessage("Can not construct instance of java.lang.Integer from String value (\"what\")");
+ thrown.expectMessage(startsWith("Cannot deserialize value of type `java.lang.Integer` from String \"what\": not a valid Integer value"));
OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/json/simplePropertiesInArrayItem.json"), Array.newInstance(genType, 0).getClass());
}
diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/PlainYamlRealExamplesIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/PlainYamlRealExamplesIT.java
new file mode 100644
index 000000000..714a49124
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/PlainYamlRealExamplesIT.java
@@ -0,0 +1,77 @@
+/**
+ * Copyright © 2010-2017 Nokia
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jsonschema2pojo.integration.yaml;
+
+import static org.hamcrest.Matchers.*;
+import static org.jsonschema2pojo.integration.util.CodeGenerationHelper.*;
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.jsonschema2pojo.integration.util.Jsonschema2PojoRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+
+public class PlainYamlRealExamplesIT {
+
+ @Rule public Jsonschema2PojoRule schemaRule = new Jsonschema2PojoRule();
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(new YAMLFactory());
+
+ @Test
+ public void getUserDataProducesValidTypes() throws Exception {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/examples/GetUserData.yaml", "com.example",
+ config("sourceType", "yaml",
+ "useLongIntegers", true));
+
+ Class> userDataType = resultsClassLoader.loadClass("com.example.GetUserData");
+
+ Object userData = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/yaml/examples/GetUserData.yaml"), userDataType);
+ Object result = userDataType.getMethod("getResult").invoke(userData);
+ Object data = result.getClass().getMethod("getData").invoke(result);
+ Object userUIPref = data.getClass().getMethod("getUserUIPref").invoke(data);
+
+ assertThat(userUIPref.getClass().getMethod("getPimColor").invoke(userUIPref).toString(), is("blue"));
+
+ Object externalAccounts = data.getClass().getMethod("getExternalAccounts").invoke(data);
+ Object extAccount = externalAccounts.getClass().getMethod("getExtAccount").invoke(externalAccounts);
+ Object extAccount0 = ((List>) extAccount).get(0);
+ assertThat(extAccount0.getClass().getMethod("getFolder").invoke(extAccount0).toString(), is("Inbox"));
+
+ }
+
+ @Test
+ public void torrentProducesValidTypes() throws Exception {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/examples/torrent.yaml", "com.example",
+ config("sourceType", "yaml",
+ "propertyWordDelimiters", "_"));
+
+ Class> torrentType = resultsClassLoader.loadClass("com.example.Torrent");
+
+ Object torrent = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/yaml/examples/torrent.yaml"), torrentType);
+
+ Object props = torrentType.getMethod("getProps").invoke(torrent);
+ Object prop0 = ((List>) props).get(0);
+ assertThat((Integer) prop0.getClass().getMethod("getSeedRatio").invoke(prop0), is(1500));
+
+ }
+}
diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/PlainYamlTypesIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/PlainYamlTypesIT.java
new file mode 100644
index 000000000..63dc5c6f3
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/PlainYamlTypesIT.java
@@ -0,0 +1,198 @@
+/**
+ * Copyright © 2010-2017 Nokia
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jsonschema2pojo.integration.yaml;
+
+import static java.util.Arrays.*;
+import static org.hamcrest.Matchers.*;
+import static org.jsonschema2pojo.integration.util.CodeGenerationHelper.*;
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.math.BigInteger;
+import java.util.List;
+
+import org.jsonschema2pojo.integration.util.Jsonschema2PojoRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.exc.InvalidFormatException;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+
+public class PlainYamlTypesIT {
+
+ @Rule
+ public Jsonschema2PojoRule schemaRule = new Jsonschema2PojoRule();
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(new YAMLFactory());
+
+ @Test
+ public void simpleTypesInExampleAreMappedToCorrectJavaTypes() throws Exception {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/simpleTypes.yaml", "com.example",
+ config("sourceType", "yaml"));
+
+ Class> generatedType = resultsClassLoader.loadClass("com.example.SimpleTypes");
+
+ Object deserialisedValue = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/yaml/simpleTypes.yaml"), generatedType);
+
+ assertThat((String) generatedType.getMethod("getA").invoke(deserialisedValue), is("abc"));
+ assertThat((Integer) generatedType.getMethod("getB").invoke(deserialisedValue), is(123));
+ assertThat((Double) generatedType.getMethod("getC").invoke(deserialisedValue), is(12999999999999999999999.99d));
+ assertThat((Boolean) generatedType.getMethod("getD").invoke(deserialisedValue), is(true));
+ assertThat(generatedType.getMethod("getE").invoke(deserialisedValue), is(nullValue()));
+
+ }
+
+ @Test
+ public void integerIsMappedToBigInteger() throws Exception {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/simpleTypes.yaml", "com.example", config("sourceType", "yaml", "useBigIntegers", true));
+
+ Class> generatedType = resultsClassLoader.loadClass("com.example.SimpleTypes");
+
+ Object deserialisedValue = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/yaml/simpleTypes.yaml"), generatedType);
+
+ assertThat((BigInteger) generatedType.getMethod("getB").invoke(deserialisedValue), is(new BigInteger("123")));
+ }
+
+ @Test(expected = ClassNotFoundException.class)
+ public void simpleTypeAtRootProducesNoJavaTypes() throws ClassNotFoundException {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/simpleTypeAsRoot.yaml", "com.example",
+ config("sourceType", "yaml"));
+
+ resultsClassLoader.loadClass("com.example.SimpleTypeAsRoot");
+
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void complexTypesProduceObjects() throws Exception {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/complexObject.yaml", "com.example",
+ config("sourceType", "yaml"));
+
+ Class> complexObjectClass = resultsClassLoader.loadClass("com.example.ComplexObject");
+ Object complexObject = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/yaml/complexObject.yaml"), complexObjectClass);
+
+ Object a = complexObjectClass.getMethod("getA").invoke(complexObject);
+ Object aa = a.getClass().getMethod("getAa").invoke(a);
+ assertThat(aa.getClass().getMethod("getAaa").invoke(aa).toString(), is("aaaa"));
+
+ Object b = complexObjectClass.getMethod("getB").invoke(complexObject);
+ assertThat(b.getClass().getMethod("getAa").invoke(b), is(notNullValue()));
+
+ Object _1 = complexObjectClass.getMethod("get1").invoke(complexObject);
+ Object _2 = _1.getClass().getMethod("get2").invoke(_1);
+ assertThat(_2, is(notNullValue()));
+ Object _3 = _1.getClass().getMethod("get3").invoke(_1);
+ assertThat((List) _3, is(equalTo(asList(1, 2, 3))));
+
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void arrayTypePropertiesProduceLists() throws Exception {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/array.yaml", "com.example",
+ config("sourceType", "yaml"));
+
+ Class> arrayType = resultsClassLoader.loadClass("com.example.Array");
+ Class> itemType = resultsClassLoader.loadClass("com.example.A");
+
+ Object deserialisedValue = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/yaml/array.yaml"), arrayType);
+
+ List> valueA = (List) arrayType.getMethod("getA").invoke(deserialisedValue);
+ assertThat(((ParameterizedType) arrayType.getMethod("getA").getGenericReturnType()).getActualTypeArguments()[0], is(equalTo((Type) itemType)));
+ assertThat((Integer) itemType.getMethod("get0").invoke(valueA.get(0)), is(0));
+ assertThat((Integer) itemType.getMethod("get1").invoke(valueA.get(1)), is(1));
+ assertThat((Integer) itemType.getMethod("get2").invoke(valueA.get(2)), is(2));
+
+ Object valueB = arrayType.getMethod("getB").invoke(deserialisedValue);
+ assertThat(valueB, is(instanceOf(List.class)));
+ assertThat(((ParameterizedType) arrayType.getMethod("getB").getGenericReturnType()).getActualTypeArguments()[0], is(equalTo((Type) Integer.class)));
+
+ }
+
+ @Test
+ public void arrayItemsAreRecursivelyMerged() throws Exception {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/complexPropertiesInArrayItem.yaml", "com.example", config("sourceType", "yaml"));
+ Class> genType = resultsClassLoader.loadClass("com.example.ComplexPropertiesInArrayItem");
+ Class> listItemType = resultsClassLoader.loadClass("com.example.List");
+ Class> objItemType = resultsClassLoader.loadClass("com.example.Obj");
+
+ Object[] items = (Object[]) OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/yaml/complexPropertiesInArrayItem.yaml"), Array.newInstance(genType, 0).getClass());
+ {
+ Object item = items[0];
+
+ List> itemList = (List>) genType.getMethod("getList").invoke(item);
+ assertThat((Integer) listItemType.getMethod("getA").invoke(itemList.get(0)), is(1));
+ assertThat((String) listItemType.getMethod("getC").invoke(itemList.get(0)), is("hey"));
+ assertNull(listItemType.getMethod("getB").invoke(itemList.get(0)));
+
+ Object itemObj = genType.getMethod("getObj").invoke(item);
+ assertThat((String) objItemType.getMethod("getName").invoke(itemObj), is("k"));
+ assertNull(objItemType.getMethod("getIndex").invoke(itemObj));
+ }
+ {
+ Object item = items[1];
+
+ List> itemList = (List>) genType.getMethod("getList").invoke(item);
+ assertThat((Integer) listItemType.getMethod("getB").invoke(itemList.get(0)), is(177));
+ assertThat((String) listItemType.getMethod("getC").invoke(itemList.get(0)), is("hey again"));
+ assertNull(listItemType.getMethod("getA").invoke(itemList.get(0)));
+
+ Object itemObj = genType.getMethod("getObj").invoke(item);
+ assertThat((Integer) objItemType.getMethod("getIndex").invoke(itemObj), is(8));
+ assertNull(objItemType.getMethod("getName").invoke(itemObj));
+ }
+ }
+
+ @Test
+ public void arrayItemsAreNotRecursivelyMerged() throws Exception {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/simplePropertiesInArrayItem.yaml", "com.example", config("sourceType", "yaml"));
+ Class> genType = resultsClassLoader.loadClass("com.example.SimplePropertiesInArrayItem");
+
+ // Different array items use different types for the same property;
+ // we don't support union types, so we have to pick one
+ assertEquals(Integer.class, genType.getMethod("getScalar").getReturnType());
+
+ thrown.expect(InvalidFormatException.class);
+ thrown.expectMessage(startsWith("Cannot deserialize value of type `java.lang.Integer` from String \"what\": not a valid Integer value"));
+ OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/yaml/simplePropertiesInArrayItem.yaml"), Array.newInstance(genType, 0).getClass());
+ }
+
+ @Test(expected = ClassNotFoundException.class)
+ public void arrayAtRootProducesNoJavaTypes() throws Exception {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/yaml/arrayAsRoot.yaml", "com.example",
+ config("sourceType", "yaml"));
+
+ resultsClassLoader.loadClass("com.example.ArrayAsRoot");
+
+ }
+
+}
diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/YamlPropertiesIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/YamlPropertiesIT.java
new file mode 100644
index 000000000..fd3fde895
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/YamlPropertiesIT.java
@@ -0,0 +1,156 @@
+/**
+ * Copyright © 2010-2017 Nokia
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jsonschema2pojo.integration.yaml;
+
+import static org.hamcrest.Matchers.*;
+import static org.jsonschema2pojo.integration.util.CodeGenerationHelper.*;
+import static org.junit.Assert.*;
+
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.jsonschema2pojo.integration.util.Jsonschema2PojoRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class YamlPropertiesIT {
+
+ @Rule public Jsonschema2PojoRule schemaRule = new Jsonschema2PojoRule();
+
+ private final ObjectMapper mapper = new ObjectMapper();
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void propertiesWithNullValuesAreOmittedWhenSerialized() throws ClassNotFoundException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/yaml/properties/nullProperties.yaml", "com.example", config("sourceType", "yamlschema"));
+
+ Class generatedType = resultsClassLoader.loadClass("com.example.NullProperties");
+ Object instance = generatedType.newInstance();
+
+ Method setter = new PropertyDescriptor("property", generatedType).getWriteMethod();
+ setter.invoke(instance, "value");
+
+ assertThat(mapper.valueToTree(instance).toString(), containsString("property"));
+
+ setter.invoke(instance, (Object) null);
+
+ assertThat(mapper.valueToTree(instance).toString(), not(containsString("property")));
+
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void usePrimitivesArgumentCausesPrimitiveTypes() throws ClassNotFoundException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/yaml/properties/primitiveProperties.yaml", "com.example", config("usePrimitives", true, "sourceType", "yamlschema"));
+
+ Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties");
+
+ assertThat(new PropertyDescriptor("a", generatedType).getReadMethod().getReturnType().getName(), is("int"));
+ assertThat(new PropertyDescriptor("b", generatedType).getReadMethod().getReturnType().getName(), is("double"));
+ assertThat(new PropertyDescriptor("c", generatedType).getReadMethod().getReturnType().getName(), is("boolean"));
+
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void wordDelimitersCausesCamelCase() throws ClassNotFoundException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/yaml/properties/propertiesWithWordDelimiters.yaml", "com.example",
+ config("usePrimitives", true, "propertyWordDelimiters", "_ -", "sourceType", "yamlschema"));
+
+ Class generatedType = resultsClassLoader.loadClass("com.example.WordDelimit");
+
+ Object instance = generatedType.newInstance();
+
+ new PropertyDescriptor("propertyWithUnderscores", generatedType).getWriteMethod().invoke(instance, "a_b_c");
+ new PropertyDescriptor("propertyWithHyphens", generatedType).getWriteMethod().invoke(instance, "a-b-c");
+ new PropertyDescriptor("propertyWithMixedDelimiters", generatedType).getWriteMethod().invoke(instance, "a b_c-d");
+
+ JsonNode jsonified = mapper.valueToTree(instance);
+
+ assertThat(jsonified.has("property_with_underscores"), is(true));
+ assertThat(jsonified.has("property-with-hyphens"), is(true));
+ assertThat(jsonified.has("property_with mixed-delimiters"), is(true));
+ }
+
+ @Test
+ public void propertyNamesThatAreJavaKeywordsCanBeSerialized() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/yaml/properties/propertiesThatAreJavaKeywords.yaml", "com.example", config("sourceType", "yamlschema"));
+
+ Class> generatedType = resultsClassLoader.loadClass("com.example.PropertiesThatAreJavaKeywords");
+
+ String valuesAsJsonString = "{\"public\":\"a\",\"void\":\"b\",\"enum\":\"c\",\"abstract\":\"d\"}";
+ Object valuesAsObject = mapper.readValue(valuesAsJsonString, generatedType);
+ JsonNode valueAsJsonNode = mapper.valueToTree(valuesAsObject);
+
+ assertThat(valueAsJsonNode.path("public").asText(), is("a"));
+ assertThat(valueAsJsonNode.path("void").asText(), is("b"));
+ assertThat(valueAsJsonNode.path("enum").asText(), is("c"));
+ assertThat(valueAsJsonNode.path("abstract").asText(), is("d"));
+
+ }
+
+ @Test
+ public void propertyCalledClassCanBeSerialized() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
+
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/yaml/properties/propertyCalledClass.yaml", "com.example", config("sourceType", "yamlschema"));
+
+ Class> generatedType = resultsClassLoader.loadClass("com.example.PropertyCalledClass");
+
+ String valuesAsJsonString = "{\"class\":\"a\"}";
+ Object valuesAsObject = mapper.readValue(valuesAsJsonString, generatedType);
+ JsonNode valueAsJsonNode = mapper.valueToTree(valuesAsObject);
+
+ assertThat(valueAsJsonNode.path("class").asText(), is("a"));
+
+ }
+
+ @Test
+ public void propertyNamesAreLowerCamelCase() throws Exception {
+ ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/yaml/properties/propertiesAreUpperCamelCase.yaml", "com.example", config("sourceType", "yamlschema"));
+ Class> generatedType = resultsClassLoader.loadClass("com.example.UpperCase");
+
+ Object instance = generatedType.newInstance();
+
+ new PropertyDescriptor("property1", generatedType).getWriteMethod().invoke(instance, "1");
+ new PropertyDescriptor("propertyTwo", generatedType).getWriteMethod().invoke(instance, 2);
+ new PropertyDescriptor("propertyThreeWithSpace", generatedType).getWriteMethod().invoke(instance, "3");
+ new PropertyDescriptor("propertyFour", generatedType).getWriteMethod().invoke(instance, "4");
+
+ JsonNode jsonified = mapper.valueToTree(instance);
+
+ assertNotNull(generatedType.getDeclaredField("property1"));
+ assertNotNull(generatedType.getDeclaredField("propertyTwo"));
+ assertNotNull(generatedType.getDeclaredField("propertyThreeWithSpace"));
+ assertNotNull(generatedType.getDeclaredField("propertyFour"));
+
+ assertThat(jsonified.has("Property1"), is(true));
+ assertThat(jsonified.has("PropertyTwo"), is(true));
+ assertThat(jsonified.has(" PropertyThreeWithSpace"), is(true));
+ assertThat(jsonified.has("propertyFour"), is(true));
+ }
+
+}
diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/YamlRefIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/YamlRefIT.java
new file mode 100644
index 000000000..445daa0ee
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/YamlRefIT.java
@@ -0,0 +1,21 @@
+/**
+ * Copyright © 2010-2017 Nokia
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jsonschema2pojo.integration.yaml;
+
+public class YamlRefIT {
+
+}
diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/YamlTypeIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/YamlTypeIT.java
new file mode 100644
index 000000000..0f8544d8f
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/yaml/YamlTypeIT.java
@@ -0,0 +1,353 @@
+/**
+ * Copyright © 2010-2017 Nokia
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jsonschema2pojo.integration.yaml;
+
+import static org.hamcrest.Matchers.*;
+import static org.jsonschema2pojo.integration.util.CodeGenerationHelper.*;
+import static org.junit.Assert.*;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Collection;
+
+import org.jsonschema2pojo.integration.util.Jsonschema2PojoRule;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class YamlTypeIT {
+ @ClassRule public static Jsonschema2PojoRule classSchemaRule = new Jsonschema2PojoRule();
+ @Rule public Jsonschema2PojoRule schemaRule = new Jsonschema2PojoRule();
+
+ private static Class> classWithManyTypes;
+
+ @BeforeClass
+ public static void generateAndCompileClass() throws ClassNotFoundException {
+ classWithManyTypes = classSchemaRule.generateAndCompile("/schema/yaml/type/types.yaml", "com.example", config("sourceType", "yamlschema"))
+ .loadClass("com.example.Types");
+ }
+
+ @Test
+ public void booleanTypeProducesBooleans() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getBooleanProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Boolean"));
+
+ }
+
+ @Test
+ public void stringTypeProducesStrings() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getStringProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.String"));
+
+ }
+
+ @Test
+ public void integerTypeProducesInts() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getIntegerProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Integer"));
+
+ }
+
+ @Test
+ public void numberTypeProducesDouble() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getNumberProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Double"));
+
+ }
+
+ @Test
+ public void arrayTypeProducesCollection() throws NoSuchMethodException, ClassNotFoundException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getArrayProperty");
+
+ assertThat(Collection.class.isAssignableFrom(getterMethod.getReturnType()), is(true));
+
+ }
+
+ @Test
+ public void nullTypeProducesObject() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getNullProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Object"));
+
+ }
+
+ @Test
+ public void anyTypeProducesObject() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getAnyProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Object"));
+
+ }
+
+ @Test
+ public void presenceOfPropertiesImpliesTypeObject() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getImpliedObjectProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("com.example.ImpliedObjectProperty"));
+
+ }
+
+ @Test
+ public void objectTypeProducesNewType() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getObjectProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("com.example.ObjectProperty"));
+ assertThat(getterMethod.getReturnType().getMethod("getProperty"), is(notNullValue()));
+
+ }
+
+ @Test
+ public void defaultTypeProducesObject() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getDefaultProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Object"));
+
+ }
+
+ @Test
+ public void reusingTypeFromClasspathProducesNoNewType() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getReusedClasspathType");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.util.Locale"));
+ assertThat(classSchemaRule.generated("java/util/Locale.java").exists(), is(false));
+
+ }
+
+ @Test
+ public void reusingTypeFromGeneratedTypesProducesNoNewType() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getReusedGeneratedType");
+
+ assertThat(getterMethod.getReturnType().getName(), is("com.example.ObjectProperty"));
+ assertThat(getterMethod.getReturnType().getMethod("getProperty"), is(notNullValue()));
+
+ }
+
+ @Test
+ public void javaTypeSupportsPrimitiveTypes() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getPrimitiveJavaType");
+
+ assertThat(getterMethod.getReturnType().getName(), is("long"));
+
+ }
+
+ @Test
+ public void correctTypeIsChosenForNullableType() throws NoSuchMethodException {
+
+ Method getterMethod = classWithManyTypes.getMethod("getNullableStringProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.String"));
+
+ }
+
+ @Test
+ public void javaTypeCanBeUsedForAnyShemaType() throws NoSuchMethodException {
+
+ assertThat(classWithManyTypes.getMethod("getIntegerWithJavaType").getReturnType().getName(), is("java.math.BigDecimal"));
+ assertThat(classWithManyTypes.getMethod("getNumberWithJavaType").getReturnType().getName(), is("java.util.UUID"));
+ assertThat(classWithManyTypes.getMethod("getStringWithJavaType").getReturnType().getName(), is("java.lang.Boolean"));
+ assertThat(classWithManyTypes.getMethod("getBooleanWithJavaType").getReturnType().getName(), is("long"));
+ assertThat(classWithManyTypes.getMethod("getDateWithJavaType").getReturnType().getName(), is("int"));
+
+ }
+
+ @Test
+ public void maximumGreaterThanIntegerMaxCausesIntegersToBecomeLongs() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+ Class> classWithLongProperty = schemaRule.generateAndCompile("/schema/yaml/type/integerWithLongMaximumAsLong.yaml", "com.example", config("sourceType", "yamlschema"))
+ .loadClass("com.example.IntegerWithLongMaximumAsLong");
+
+ Method getterMethod = classWithLongProperty.getMethod("getLongProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Long"));
+
+ }
+
+ @Test
+ public void maximumGreaterThanIntegerMaxCausesIntegersToBecomePrimitiveLongs() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+ Class> classWithLongProperty = schemaRule.generateAndCompile("/schema/yaml/type/integerWithLongMaximumAsLong.yaml", "com.example", config("usePrimitives", true, "sourceType", "yamlschema"))
+ .loadClass("com.example.IntegerWithLongMaximumAsLong");
+
+ Method getterMethod = classWithLongProperty.getMethod("getLongProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("long"));
+
+ }
+
+ @Test
+ public void minimumLessThanIntegerMinCausesIntegersToBecomeLongs() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+ Class> classWithLongProperty = schemaRule.generateAndCompile("/schema/yaml/type/integerWithLongMinimumAsLong.yaml", "com.example", config("sourceType", "yamlschema"))
+ .loadClass("com.example.IntegerWithLongMinimumAsLong");
+
+ Method getterMethod = classWithLongProperty.getMethod("getLongProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Long"));
+
+ }
+
+ @Test
+ public void minimumLessThanIntegerMinCausesIntegersToBecomePrimitiveLongs() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+ Class> classWithLongProperty = schemaRule.generateAndCompile("/schema/yaml/type/integerWithLongMinimumAsLong.yaml", "com.example", config("usePrimitives", true, "sourceType", "yamlschema"))
+ .loadClass("com.example.IntegerWithLongMinimumAsLong");
+
+ Method getterMethod = classWithLongProperty.getMethod("getLongProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("long"));
+
+ }
+
+ @Test
+ public void useLongIntegersParameterCausesIntegersToBecomeLongs() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+ Class> classWithLongProperty = schemaRule.generateAndCompile("/schema/yaml/type/integerAsLong.yaml", "com.example", config("useLongIntegers", true, "sourceType", "yamlschema"))
+ .loadClass("com.example.IntegerAsLong");
+
+ Method getterMethod = classWithLongProperty.getMethod("getLongProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Long"));
+
+ }
+
+ @Test
+ public void useLongIntegersParameterCausesPrimitiveIntsToBecomeLongs() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+ Class> classWithLongProperty = schemaRule.generateAndCompile("/schema/yaml/type/integerAsLong.yaml", "com.example", config("useLongIntegers", true, "usePrimitives", true, "sourceType", "yamlschema"))
+ .loadClass("com.example.IntegerAsLong");
+
+ Method getterMethod = classWithLongProperty.getMethod("getLongProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("long"));
+ }
+
+ @Test
+ public void useDoubleNumbersFalseCausesNumbersToBecomeFloats() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+ Class> classWithDoubleProperty = schemaRule.generateAndCompile("/schema/yaml/type/numberAsFloat.yaml", "com.example", config("useDoubleNumbers", false, "sourceType", "yamlschema"))
+ .loadClass("com.example.NumberAsFloat");
+
+ Method getterMethod = classWithDoubleProperty.getMethod("getFloatProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("java.lang.Float"));
+
+ }
+
+ @Test
+ public void useDoubleNumbersFalseCausesPrimitiveNumbersToBecomeFloats() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+ Class> classWithDoubleProperty = schemaRule.generateAndCompile("/schema/yaml/type/numberAsFloat.yaml", "com.example", config("useDoubleNumbers", false, "usePrimitives", true, "sourceType", "yamlschema"))
+ .loadClass("com.example.NumberAsFloat");
+
+ Method getterMethod = classWithDoubleProperty.getMethod("getFloatProperty");
+
+ assertThat(getterMethod.getReturnType().getName(), is("float"));
+ }
+
+ @Test
+ public void unionTypesChooseFirstTypePresent() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
+
+ Class> classWithUnionProperties = schemaRule.generateAndCompile("/schema/yaml/type/unionTypes.yaml", "com.example", config("sourceType", "yamlschema")).loadClass("com.example.UnionTypes");
+
+ Method booleanGetter = classWithUnionProperties.getMethod("getBooleanProperty");
+
+ assertThat(booleanGetter.getReturnType().getName(), is("java.lang.Boolean"));
+
+ Method stringGetter = classWithUnionProperties.getMethod("getStringProperty");
+
+ assertThat(stringGetter.getReturnType().getName(), is("java.lang.String"));
+
+ Method integerGetter = classWithUnionProperties.getMethod("getIntegerProperty");
+
+ assertThat(integerGetter.getReturnType().getName(), is("java.lang.Integer"));
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void typeNameConflictDoesNotCauseTypeReuse() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+ Class> classWithNameConflict = schemaRule.generateAndCompile("/schema/yaml/type/typeNameConflict.yaml", "com.example", config("sourceType", "yamlschema")).loadClass("com.example.TypeNameConflict");
+
+ Method getterMethod = classWithNameConflict.getMethod("getTypeNameConflict");
+
+ assertThat((Class) getterMethod.getReturnType(), is(not((Class) classWithNameConflict)));
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void typeImplementsAdditionalJavaInterfaces() throws NoSuchMethodException {
+ Method getterMethod = classWithManyTypes.getMethod("getTypeWithInterfaces");
+
+ assertThat(getterMethod.getReturnType().getName(), is("com.example.TypeWithInterfaces"));
+ assertThat(getterMethod.getReturnType().getInterfaces().length, is(2));
+ assertThat((Class[]) getterMethod.getReturnType().getInterfaces(), hasItemInArray((Class) Cloneable.class));
+ assertThat((Class[]) getterMethod.getReturnType().getInterfaces(), hasItemInArray((Class) Serializable.class));
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void typeImplementsInterfacesWithGenericArgsCorrectly() throws NoSuchMethodException, SecurityException {
+ Method getterMethod = classWithManyTypes.getMethod("getTypeWithGenericInterface");
+
+ assertThat(getterMethod.getReturnType().getName(), is("com.example.TypeWithGenericInterface"));
+ assertThat(getterMethod.getReturnType().getInterfaces().length, is(1));
+ assertThat((Class[]) getterMethod.getReturnType().getInterfaces(), hasItemInArray((Class) InterfaceWithGenerics.class));
+ }
+
+ public interface InterfaceWithGenerics {
+ }
+
+ @Test
+ public void typeExtendsJavaClass() throws NoSuchMethodException {
+ Method getterMethod = classWithManyTypes.getMethod("getTypeWithInheritedClass");
+
+ final Class> generatedClass = getterMethod.getReturnType();
+ assertThat(generatedClass.getName(), is("com.example.TypeWithInheritedClass"));
+ assertThat(generatedClass.getSuperclass().equals(InheritedClass.class), equalTo(true));
+ }
+
+ public static class InheritedClass {
+ }
+
+ @Test
+ public void typeExtendsJavaClassWithGenerics() throws NoSuchMethodException {
+ Method getterMethod = classWithManyTypes.getMethod("getTypeWithInheritedClassWithGenerics");
+
+ final Class> generatedClass = getterMethod.getReturnType();
+ assertThat(generatedClass.getName(), is("com.example.TypeWithInheritedClassWithGenerics"));
+ assertThat(generatedClass.getSuperclass().equals(InheritedClassWithGenerics.class), equalTo(true));
+ assertThat(((ParameterizedType) generatedClass.getGenericSuperclass()).getActualTypeArguments(), equalTo(new Type[]
+ {
+ String.class, Integer.class, Boolean.class
+ }));
+ }
+
+ public static class InheritedClassWithGenerics {
+ }
+
+}
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/initializeCollectionProperties.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/initializeCollectionProperties.yaml
new file mode 100644
index 000000000..7d5b1748a
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/initializeCollectionProperties.yaml
@@ -0,0 +1,20 @@
+properties:
+ list:
+ type: array
+ listWithValues:
+ default:
+ - 100
+ - 200
+ - 300
+ type: array
+ set:
+ type: array
+ uniqueItems: true
+ setWithValues:
+ default:
+ - 100
+ - 200
+ - 300
+ type: array
+ uniqueItems: true
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/nonStandardRef.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/nonStandardRef.yaml
new file mode 100644
index 000000000..e9a6546d9
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/nonStandardRef.yaml
@@ -0,0 +1,11 @@
+additionalProperties: false
+definitions:
+ com.example.Foo:
+ properties:
+ bar:
+ type: string
+ type: object
+properties:
+ foo:
+ $ref: '#/definitions/com.example.Foo'
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/nullProperties.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/nullProperties.yaml
new file mode 100644
index 000000000..84dea6d58
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/nullProperties.yaml
@@ -0,0 +1,4 @@
+properties:
+ property:
+ type: string
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/objectPropertiesJavaType.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/objectPropertiesJavaType.yaml
new file mode 100644
index 000000000..9d6a36459
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/objectPropertiesJavaType.yaml
@@ -0,0 +1,5 @@
+properties:
+ a:
+ javaType: org.jsonschema2pojo.NoopAnnotator
+ type: object
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/primitiveProperties.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/primitiveProperties.yaml
new file mode 100644
index 000000000..577cd73c5
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/primitiveProperties.yaml
@@ -0,0 +1,9 @@
+javaType: com.example.PrimitiveProperties
+properties:
+ a:
+ type: integer
+ b:
+ type: number
+ c:
+ type: boolean
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/primitivePropertiesNoJavaType.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/primitivePropertiesNoJavaType.yaml
new file mode 100644
index 000000000..56a1c6f52
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/primitivePropertiesNoJavaType.yaml
@@ -0,0 +1,8 @@
+properties:
+ a:
+ type: integer
+ b:
+ type: number
+ c:
+ type: boolean
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertiesAreUpperCamelCase.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertiesAreUpperCamelCase.yaml
new file mode 100644
index 000000000..03e192b18
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertiesAreUpperCamelCase.yaml
@@ -0,0 +1,11 @@
+javaType: com.example.UpperCase
+properties:
+ ' PropertyThreeWithSpace':
+ type: string
+ Property1:
+ type: string
+ PropertyTwo:
+ type: integer
+ propertyFour:
+ type: string
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertiesThatAreJavaKeywords.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertiesThatAreJavaKeywords.yaml
new file mode 100644
index 000000000..95b62f45a
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertiesThatAreJavaKeywords.yaml
@@ -0,0 +1,10 @@
+properties:
+ abstract:
+ type: string
+ enum:
+ type: string
+ public:
+ type: string
+ void:
+ type: string
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertiesWithWordDelimiters.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertiesWithWordDelimiters.yaml
new file mode 100644
index 000000000..4bd7e8731
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertiesWithWordDelimiters.yaml
@@ -0,0 +1,9 @@
+javaType: com.example.WordDelimit
+properties:
+ property-with-hyphens:
+ type: string
+ property_with mixed-delimiters:
+ type: string
+ property_with_underscores:
+ type: string
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertyCalledClass.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertyCalledClass.yaml
new file mode 100644
index 000000000..a224313f4
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/properties/propertyCalledClass.yaml
@@ -0,0 +1,4 @@
+properties:
+ class:
+ type: string
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/a.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/a.yaml
new file mode 100644
index 000000000..db109bf8f
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/a.yaml
@@ -0,0 +1,7 @@
+additionalProperties:
+ javaType: com.example.AdditionalPropertyValue
+ type: object
+properties:
+ propertyOfA:
+ type: string
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/address.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/address.yaml
new file mode 100644
index 000000000..fd0a4e2d8
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/address.yaml
@@ -0,0 +1,26 @@
+dependencies:
+ extended-address: street-address
+ locality: region
+ post-office-box: street-address
+ region: country-name
+ street-address: region
+description: An Address following the convention of http://microformats.org/wiki/hcard
+properties:
+ country-name:
+ required: true
+ type: string
+ extended-address:
+ type: string
+ locality:
+ required: true
+ type: string
+ post-office-box:
+ type: string
+ postal-code:
+ type: string
+ region:
+ required: true
+ type: string
+ street-address:
+ type: string
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/classpathRefs.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/classpathRefs.yaml
new file mode 100644
index 000000000..e489528be
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/classpathRefs.yaml
@@ -0,0 +1,10 @@
+properties:
+ propertyClasspathRef:
+ $ref: classpath:/schema/ref/a.json
+ propertyJavaRef:
+ $ref: java:/schema/description/description.json
+ propertyResourceRef:
+ $ref: resource:/schema/title/title.json
+ transitiveRelativeClasspathRef:
+ $ref: java:/schema/ref/classpathRefs2.json
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/classpathRefs2.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/classpathRefs2.yaml
new file mode 100644
index 000000000..2fad17b9c
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/classpathRefs2.yaml
@@ -0,0 +1,4 @@
+properties:
+ propertyRelativeRef:
+ $ref: classpathRefs3.json
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/classpathRefs3.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/classpathRefs3.yaml
new file mode 100644
index 000000000..3205714b7
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/classpathRefs3.yaml
@@ -0,0 +1,4 @@
+properties:
+ transitive:
+ type: string
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/fragmentRefs.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/fragmentRefs.yaml
new file mode 100644
index 000000000..49c3cf040
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/fragmentRefs.yaml
@@ -0,0 +1,9 @@
+additionalProperties: false
+properties:
+ a:
+ $ref: a.json
+ fragmentOfA:
+ $ref: a.json/#/additionalProperties
+ fragmentOfSelf:
+ $ref: '#/properties/a'
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/httpRefs.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/httpRefs.yaml
new file mode 100644
index 000000000..64dea2075
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/httpRefs.yaml
@@ -0,0 +1,6 @@
+properties:
+ address:
+ $ref: https://raw.githubusercontent.com/joelittlejohn/jsonschema2pojo/master/jsonschema2pojo-integration-tests/src/test/resources/schema/ref/address.json
+ refsToA:
+ $ref: https://raw.githubusercontent.com/joelittlejohn/jsonschema2pojo/master/jsonschema2pojo-integration-tests/src/test/resources/schema/ref/refsToA.json
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/nestedSelfRefsReadAsString.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/nestedSelfRefsReadAsString.yaml
new file mode 100644
index 000000000..2589b6117
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/nestedSelfRefsReadAsString.yaml
@@ -0,0 +1,23 @@
+definitions:
+ Name:
+ type: string
+ Namespace:
+ type: string
+ Thing:
+ properties:
+ name:
+ $ref: '#/definitions/Name'
+ namespace:
+ $ref: '#/definitions/Namespace'
+ version:
+ $ref: '#/definitions/Version'
+ ThingList:
+ items:
+ $ref: '#/definitions/Thing'
+ type: array
+ Version:
+ type: string
+properties:
+ things:
+ $ref: '#/definitions/ThingList'
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/refsToA.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/refsToA.yaml
new file mode 100644
index 000000000..b82a86d80
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/refsToA.yaml
@@ -0,0 +1,10 @@
+additionalProperties:
+ $ref: a.json
+properties:
+ a:
+ $ref: a.json
+ arrayOfA:
+ items:
+ $ref: a.json
+ type: array
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/selfRefs.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/selfRefs.yaml
new file mode 100644
index 000000000..1b77c14de
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/selfRefs.yaml
@@ -0,0 +1,23 @@
+additionalProperties:
+ $ref: '#'
+definitions:
+ embedded:
+ properties:
+ embeddedProp:
+ $ref: '#/definitions/embedded2'
+ type: object
+ embedded2:
+ properties:
+ embeddedProp2:
+ $ref: '#'
+ type: object
+properties:
+ arrayOfSelf:
+ items:
+ $ref: '#'
+ type: array
+ childOfSelf:
+ $ref: '#'
+ embeddedInSelf:
+ $ref: '#/definitions/embedded'
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/subdirectory1/refToSubdirectory2.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/subdirectory1/refToSubdirectory2.yaml
new file mode 100644
index 000000000..6584b6227
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/subdirectory1/refToSubdirectory2.yaml
@@ -0,0 +1,5 @@
+javaType: com.example.RefToSubdirectory1
+properties:
+ refToOther:
+ $ref: ../subdirectory2/refToSubdirectory1.json
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/subdirectory2/refToSubdirectory1.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/subdirectory2/refToSubdirectory1.yaml
new file mode 100644
index 000000000..da40de7db
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/ref/subdirectory2/refToSubdirectory1.yaml
@@ -0,0 +1,5 @@
+javaType: com.example.RefToSubdirectory2
+properties:
+ refToOther:
+ $ref: ../subdirectory1/refToSubdirectory2.json
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/genericJavaType.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/genericJavaType.yaml
new file mode 100644
index 000000000..13c7bd60e
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/genericJavaType.yaml
@@ -0,0 +1,13 @@
+properties:
+ a:
+ javaType: java.util.Map
+ type: object
+ b:
+ javaType: java.util.Map, java.util.List>>
+ type: object
+ c:
+ javaType: java.util.Map
+ type: object
+ d:
+ javaType: java.util.Map
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/integerAsLong.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/integerAsLong.yaml
new file mode 100644
index 000000000..ebebc504c
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/integerAsLong.yaml
@@ -0,0 +1,4 @@
+properties:
+ longProperty:
+ type: integer
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/integerWithLongMaximumAsLong.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/integerWithLongMaximumAsLong.yaml
new file mode 100644
index 000000000..26712fab1
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/integerWithLongMaximumAsLong.yaml
@@ -0,0 +1,5 @@
+properties:
+ longProperty:
+ maximum: 2147483648
+ type: integer
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/integerWithLongMinimumAsLong.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/integerWithLongMinimumAsLong.yaml
new file mode 100644
index 000000000..8ef44e4e1
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/integerWithLongMinimumAsLong.yaml
@@ -0,0 +1,5 @@
+properties:
+ longProperty:
+ minimum: -2147483649
+ type: integer
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/numberAsFloat.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/numberAsFloat.yaml
new file mode 100644
index 000000000..83ed28630
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/numberAsFloat.yaml
@@ -0,0 +1,4 @@
+properties:
+ floatProperty:
+ type: number
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/typeNameConflict.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/typeNameConflict.yaml
new file mode 100644
index 000000000..f3bd8c988
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/typeNameConflict.yaml
@@ -0,0 +1,4 @@
+properties:
+ typeNameConflict:
+ type: object
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/types.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/types.yaml
new file mode 100644
index 000000000..9368359df
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/types.yaml
@@ -0,0 +1,72 @@
+properties:
+ anyProperty:
+ type: any
+ arrayProperty:
+ type: array
+ booleanProperty:
+ type: boolean
+ booleanWithJavaType:
+ javaType: long
+ type: boolean
+ dateWithJavaType:
+ format: date-time
+ javaType: int
+ type: string
+ defaultProperty: {}
+ impliedObjectProperty:
+ properties:
+ property:
+ type: string
+ integerProperty:
+ type: integer
+ integerWithJavaType:
+ javaType: java.math.BigDecimal
+ type: integer
+ nullProperty:
+ type: 'null'
+ nullableStringProperty:
+ type:
+ - 'null'
+ - string
+ numberProperty:
+ type: number
+ numberWithJavaType:
+ javaType: java.util.UUID
+ type: number
+ objectProperty:
+ properties:
+ property:
+ type: string
+ type: object
+ primitiveJavaType:
+ javaType: long
+ type: object
+ reusedClasspathType:
+ javaType: java.util.Locale
+ type: object
+ reusedGeneratedType:
+ javaType: com.example.ObjectProperty
+ type: object
+ stringProperty:
+ type: string
+ stringWithJavaType:
+ javaType: java.lang.Boolean
+ type: string
+ typeWithGenericInterface:
+ javaInterfaces:
+ - org.jsonschema2pojo.integration.yaml.YamlTypeIT.InterfaceWithGenerics
+ type: object
+ typeWithInheritedClass:
+ extendsJavaClass: org.jsonschema2pojo.integration.yaml.YamlTypeIT.InheritedClass
+ type: object
+ typeWithInheritedClassWithGenerics:
+ extendsJavaClass: org.jsonschema2pojo.integration.yaml.YamlTypeIT.InheritedClassWithGenerics
+ type: object
+ typeWithInterfaces:
+ javaInterfaces:
+ - java.io.Serializable
+ - Cloneable
+ type: object
+ unknownProperty:
+ type: some-unknown-type
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/unionTypes.yaml b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/unionTypes.yaml
new file mode 100644
index 000000000..2f5011166
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/yaml/type/unionTypes.yaml
@@ -0,0 +1,13 @@
+properties:
+ booleanProperty:
+ type:
+ - boolean
+ - string
+ integerProperty:
+ type:
+ - integer
+ - 'null'
+ stringProperty:
+ type:
+ - string
+type: object
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/array.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/array.yaml
new file mode 100644
index 000000000..4935f8018
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/yaml/array.yaml
@@ -0,0 +1,8 @@
+a:
+- '0': 0
+- '1': 1
+- '2': 2
+b:
+- 1
+- 2
+- 3
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/arrayAsRoot.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/arrayAsRoot.yaml
new file mode 100644
index 000000000..a0cd6f382
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/yaml/arrayAsRoot.yaml
@@ -0,0 +1,3 @@
+- 1
+- 2
+- 3
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/comments.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/comments.yaml
new file mode 100644
index 000000000..e69de29bb
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/complexObject.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/complexObject.yaml
new file mode 100644
index 000000000..51b823ea8
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/yaml/complexObject.yaml
@@ -0,0 +1,12 @@
+'1':
+ '2': {}
+ '3':
+ - 1
+ - 2
+ - 3
+a:
+ aa:
+ aaa: aaaa
+b:
+ aa:
+ ccc: dddd
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/complexPropertiesInArrayItem.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/complexPropertiesInArrayItem.yaml
new file mode 100644
index 000000000..cde7bb69c
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/yaml/complexPropertiesInArrayItem.yaml
@@ -0,0 +1,10 @@
+- list:
+ - a: 1
+ c: hey
+ obj:
+ name: k
+- list:
+ - b: 177
+ c: hey again
+ obj:
+ index: 8
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/examples/GetUserData.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/examples/GetUserData.yaml
new file mode 100644
index 000000000..3955d257d
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/yaml/examples/GetUserData.yaml
@@ -0,0 +1,145 @@
+id: c58b64ca-7e83-404f-ab2a-f4666ade521f
+result:
+ data:
+ aliases:
+ alias:
+ - address: gergergerger@gerger.de
+ isDefault: false
+ aliasesTotal: 1
+ blockedAddresses:
+ blockedAddress: []
+ blockedAddressesMax: 500
+ blockedAddressesTotal: 0
+ disposableAddresses:
+ deaDomain: bvdfbdg.fd
+ deaNamesTotal: 0
+ externalAccounts:
+ extAccount:
+ - accountName: rget4nhrthjrth
+ address: htrhtr@hrhtrhtr.de
+ colorIndicator: ' '
+ folder: Inbox
+ fromName: ''
+ isDefault: false
+ leaveMail: true
+ mailFromAllowed: true
+ port: '995'
+ protocol: pop3
+ replyTo: ''
+ retrieveOnlyNew: true
+ server: rgerghehtr
+ sslFlag: true
+ useFilters: true
+ username: ferfergergerge
+ extAccountsTotal: 1
+ filters:
+ filtersMax: 100
+ mobileFiltersMax: '100'
+ numberOfFilters: 8
+ numberOfMailFilters: 8
+ numberOfMobileFilters: 0
+ otherYahooMboxes:
+ otherYahooMboxesTotal: 0
+ yMbox: []
+ switches:
+ noFormWarning: false
+ userFeaturePref:
+ attachFileSize: 26214400
+ attachFiles: 50
+ attachTotalEncodedSize: 34865152
+ attachTotalSize: 26214400
+ btTier: ''
+ bulkAction: 0
+ domainMembership: ''
+ filtersMax: 100
+ governingJurisdiction: pl
+ hasAddressGuard: true
+ hasAds: true
+ hasAliasEnabled: true
+ hasArchiving: false
+ hasForwarding: true
+ hasMailPlus: false
+ hasStationery: false
+ intl: pl
+ isMaster: false
+ isMobileDeviceRegistered: false
+ isPremium: false
+ isThreadingEnabled: true
+ isUpsellEnabled: true
+ mailCheckInterval: 1
+ mailForward: ''
+ mailRegTime: '1334726388.0'
+ mailboxQuota: 322122547200
+ mailboxQuotaMegabytes: 307200
+ mobileFiltersMax: '100'
+ optInState: '4'
+ partnerName: Yahoo!
+ partnerType: ''
+ quotaUsed: 728926165
+ quotaUsedMegabytes: 695.158162117
+ rogersTier: ''
+ silo: '132120'
+ soundNewMail: ''
+ timezone:
+ fullname: Europe/Paris
+ name: '+1'
+ ymvm: ''
+ userPopPref:
+ hasPOP: false
+ popBulkSubjectPrefix: false
+ popNoBulk: false
+ popSetupEligible: true
+ userSendPref:
+ addUnknownContact: always
+ autosaveOnSend: 'yes'
+ canSendFromPopAcct: true
+ defaultFromAddress: xxxxxxxxx@dgferger.de
+ defaultFromName: htrhtrhtrhr
+ defaultID: xxxxxxxxx@dgferger.de
+ defaultReplyToAddress: ''
+ firstName: xxxx
+ includeMsgOnReply: short
+ lastName: xxxxx
+ loggedInAlias: rghtrhtrh
+ richTextSignature: dhtml
+ showCcBcc: hide
+ signatureActive: true
+ signatureText: none
+ userSpamPref:
+ spamBlockSender: false
+ spamCleanupPeriod: 30
+ spamFilterActive: true
+ spamGuardPlusEnabled: false
+ spamMoveToInbox: 0
+ userUIPref:
+ composeFontFamily: arial, helvetica, sans-serif
+ composeFontSize: '12'
+ defaultSortOrder: down
+ goOnMessageDelete: box
+ imageBlocking: '0'
+ language: pl-PL
+ messagesPerPage: '25'
+ msgPaneVisible: true
+ newsCategory: ''
+ pimBeta: ''
+ pimColor: blue
+ pimTheme: ''
+ searchPromo: false
+ showAttachmentColumn: true
+ showCalendarStrip: false
+ showFlagColumn: true
+ showNoise: false
+ showSizeColumn: true
+ showSnippets: true
+ showTo: false
+ useRichText: dynamic
+ userVacationPref:
+ vacationAddressBookOnly: false
+ vacationResponseDomain0: ''
+ vacationResponseDomain1: ''
+ vacationResponseEndDate: ''
+ vacationResponseOn: false
+ vacationResponseSpecialText: ''
+ vacationResponseStartDate: ''
+ vacationResponseSubject: ''
+ vacationResponseText: ''
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/examples/torrent.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/examples/torrent.yaml
new file mode 100644
index 000000000..05e691b5f
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/yaml/examples/torrent.yaml
@@ -0,0 +1,12 @@
+build: 25053
+props:
+- dht: 1
+ dlrate: 0
+ hash: 71D6FC08482AEF2903C5994C4842455D5C97CD63
+ pex: 1
+ seed_override: 0
+ seed_ratio: 1500
+ seed_time: 0
+ superseed: 0
+ trackers: http://bt.rutracker.org/ann?uk=11111111\r\n\r\nhttp://retracker.local/announce\r\n\r\nhttp://ix.rutracker.net/ann?uk=111111111\r\n
+ ulrate: 0
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/simplePropertiesInArrayItem.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/simplePropertiesInArrayItem.yaml
new file mode 100644
index 000000000..c34c39374
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/yaml/simplePropertiesInArrayItem.yaml
@@ -0,0 +1,2 @@
+- scalar: what
+- scalar: 99
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/simpleTypeAsRoot.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/simpleTypeAsRoot.yaml
new file mode 100644
index 000000000..f8826a0f0
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/yaml/simpleTypeAsRoot.yaml
@@ -0,0 +1,2 @@
+true
+...
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/yaml/simpleTypes.yaml b/jsonschema2pojo-integration-tests/src/test/resources/yaml/simpleTypes.yaml
new file mode 100644
index 000000000..1bd3c1a8c
--- /dev/null
+++ b/jsonschema2pojo-integration-tests/src/test/resources/yaml/simpleTypes.yaml
@@ -0,0 +1,5 @@
+a: abc
+b: 123
+c: 12999999999999999999999.99
+d: true
+e: null
diff --git a/jsonschema2pojo-maven-plugin/pom.xml b/jsonschema2pojo-maven-plugin/pom.xml
index 73b7f3eea..82624d893 100644
--- a/jsonschema2pojo-maven-plugin/pom.xml
+++ b/jsonschema2pojo-maven-plugin/pom.xml
@@ -35,6 +35,11 @@
+
+ com.google.cloud
+ google-cloud
+ 0.19.0-alpha
+
org.jsonschema2pojo
jsonschema2pojo-core
diff --git a/pom.xml b/pom.xml
index 3634fa35d..0985aaf9d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,8 +54,7 @@
1.6
2.5
1.5.0
- 2.10.1
- 2.10
+ 2.9.1
@@ -281,7 +280,17 @@
com.fasterxml.jackson.core
jackson-databind
- 2.7.2
+ ${jackson2x.version}
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson2x.version}
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-yaml
+ ${jackson2x.version}
com.github.stefanbirkner
@@ -304,7 +313,6 @@
jsr305
3.0.1
-
com.squareup.moshi
moshi