Search in sources :

Example 11 with JType

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

the class TypeRuleTest method applyGeneratesNumberUsingJavaTypeBigDecimal.

@Test
public void applyGeneratesNumberUsingJavaTypeBigDecimal() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "number");
    objectNode.put("javaType", "java.math.BigDecimal");
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is("java.math.BigDecimal"));
}
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 12 with JType

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

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLong.

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

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

the class TypeRuleTest method applyGeneratesIntegerPrimitive.

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

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

the class TypeRuleTest method applyGeneratesBigIntegerOverridingLong.

@Test
public void applyGeneratesBigIntegerOverridingLong() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "integer");
    // isUseBigIntegers should override isUseLongIntegers
    when(config.isUseBigIntegers()).thenReturn(true);
    when(config.isUseLongIntegers()).thenReturn(true);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is(BigInteger.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 15 with JType

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

the class TypeRuleTest method applyGeneratesNumberPrimitive.

@Test
public void applyGeneratesNumberPrimitive() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "number");
    when(config.isUsePrimitives()).thenReturn(true);
    when(config.isUseDoubleNumbers()).thenReturn(true);
    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)

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