use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLongPrimitive.
@Test
public void applyGeneratesIntegerUsingJavaTypeLongPrimitive() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "integer");
objectNode.put("javaType", "long");
when(config.isUsePrimitives()).thenReturn(false);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result.fullName(), is("long"));
}
use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLongWhenMaximumLessThanIntegerMin.
@Test
public void applyGeneratesIntegerUsingJavaTypeLongWhenMaximumLessThanIntegerMin() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "integer");
objectNode.put("maximum", Integer.MIN_VALUE - 1L);
when(config.isUsePrimitives()).thenReturn(false);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result.fullName(), is(Long.class.getName()));
}
use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesNullAsObject.
@Test
public void applyGeneratesNullAsObject() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "null");
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result.fullName(), is(Object.class.getName()));
}
use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class SchemaMapper method generate.
public JType generate(JCodeModel codeModel, String className, String packageName, String json, URI schemaLocation) throws IOException {
JPackage jpackage = codeModel._package(packageName);
JsonNode schemaNode = objectMapper().readTree(json);
return ruleFactory.getSchemaRule().apply(className, schemaNode, jpackage, new Schema(schemaLocation, schemaNode, schemaNode));
}
use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class SchemaMapper method generate.
/**
* Reads a schema and adds generated types to the given code model.
*
* @param codeModel
* the java code-generation context that should be used to
* generated new types
* @param className
* the name of the parent class the represented by this schema
* @param packageName
* the target package that should be used for generated types
* @param schemaUrl
* location of the schema to be used as input
* @return The top-most type generated from the given file
* @throws IOException
* if the schema content cannot be read
*/
public JType generate(JCodeModel codeModel, String className, String packageName, URL schemaUrl) throws IOException {
JPackage jpackage = codeModel._package(packageName);
ObjectNode schemaNode = readSchema(schemaUrl);
return ruleFactory.getSchemaRule().apply(className, schemaNode, jpackage, new Schema(null, schemaNode, schemaNode));
}
Aggregations