Search in sources :

Example 46 with JPackage

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"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 47 with JPackage

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()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 48 with JPackage

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()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 49 with JPackage

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));
}
Also used : JPackage(com.sun.codemodel.JPackage) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 50 with JPackage

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));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JPackage(com.sun.codemodel.JPackage)

Aggregations

JPackage (com.sun.codemodel.JPackage)53 JCodeModel (com.sun.codemodel.JCodeModel)47 Test (org.junit.Test)47 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)44 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)44 JType (com.sun.codemodel.JType)37 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 JClass (com.sun.codemodel.JClass)7 Schema (org.jsonschema2pojo.Schema)7 RuleFactory (org.jsonschema2pojo.rules.RuleFactory)6 SchemaRule (org.jsonschema2pojo.rules.SchemaRule)4 JDefinedClass (com.sun.codemodel.JDefinedClass)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 DataList (com.linkedin.data.DataList)1 DataMap (com.linkedin.data.DataMap)1 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)1 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1