Search in sources :

Example 46 with JType

use of com.sun.codemodel.JType in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesNumberUsingJavaTypeDoublePrimitive.

@Test
public void applyGeneratesNumberUsingJavaTypeDoublePrimitive() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "number");
    objectNode.put("javaType", "double");
    when(config.isUsePrimitives()).thenReturn(false);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is("double"));
}
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 JType

use of com.sun.codemodel.JType in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLongWhenMinimumGreaterThanIntegerMax.

@Test
public void applyGeneratesIntegerUsingJavaTypeLongWhenMinimumGreaterThanIntegerMax() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "integer");
    objectNode.put("minimum", Integer.MAX_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 JType

use of com.sun.codemodel.JType in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesBigDecimal.

@Test
public void applyGeneratesBigDecimal() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "number");
    when(config.isUseBigDecimals()).thenReturn(true);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is(BigDecimal.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 JType

use of com.sun.codemodel.JType in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesNumber.

@Test
public void applyGeneratesNumber() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "number");
    when(config.isUseDoubleNumbers()).thenReturn(true);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is(Double.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 50 with JType

use of com.sun.codemodel.JType in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesBooleanPrimitive.

@Test
public void applyGeneratesBooleanPrimitive() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "boolean");
    when(config.isUsePrimitives()).thenReturn(true);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is("boolean"));
}
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)

Aggregations

JType (com.sun.codemodel.JType)65 Test (org.junit.Test)42 JCodeModel (com.sun.codemodel.JCodeModel)41 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)39 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)38 JPackage (com.sun.codemodel.JPackage)37 JVar (com.sun.codemodel.JVar)13 JBlock (com.sun.codemodel.JBlock)10 JMethod (com.sun.codemodel.JMethod)10 JClass (com.sun.codemodel.JClass)9 JDefinedClass (com.sun.codemodel.JDefinedClass)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Map (java.util.Map)5 TextNode (com.fasterxml.jackson.databind.node.TextNode)4 JClassAlreadyExistsException (com.sun.codemodel.JClassAlreadyExistsException)3 JExpression (com.sun.codemodel.JExpression)3 JFieldVar (com.sun.codemodel.JFieldVar)3 JInvocation (com.sun.codemodel.JInvocation)3 JConditional (com.sun.codemodel.JConditional)2 JSwitch (com.sun.codemodel.JSwitch)2