Search in sources :

Example 41 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project jsonschema2pojo by joelittlejohn.

the class SchemaRuleTest method enumAsRootIsGeneratedCorrectly.

@Test
public void enumAsRootIsGeneratedCorrectly() throws URISyntaxException, JClassAlreadyExistsException {
    ObjectNode schemaContent = new ObjectMapper().createObjectNode();
    ObjectNode enumNode = schemaContent.objectNode();
    enumNode.put("type", "string");
    schemaContent.set("enum", enumNode);
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    Schema schema = mock(Schema.class);
    when(schema.getContent()).thenReturn(schemaContent);
    schema.setJavaTypeIfEmpty(jclass);
    EnumRule enumRule = mock(EnumRule.class);
    when(mockRuleFactory.getEnumRule()).thenReturn(enumRule);
    when(enumRule.apply(NODE_NAME, enumNode, jclass, schema)).thenReturn(jclass);
    rule.apply(NODE_NAME, schemaContent, jclass, schema);
    verify(enumRule).apply(NODE_NAME, schemaContent, jclass, schema);
    verify(schema, atLeastOnce()).setJavaTypeIfEmpty(jclass);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JDefinedClass(com.sun.codemodel.JDefinedClass) Schema(org.jsonschema2pojo.Schema) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 42 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project jsonschema2pojo by joelittlejohn.

the class CustomDateTimeFormatIT method testCustomDateTimePatternWithDefaultTimezoneWhenFormatDateTimesConfigIsTrue.

/**
     * This tests the class generated when formatDateTimes config option is set to TRUE
     * The field should have @JsonFormat annotation with pattern defined in json schema and UTC timezone
     * It also tests the serialization and deserialization process
     * 
     * @throws Exception
     */
@Test
public void testCustomDateTimePatternWithDefaultTimezoneWhenFormatDateTimesConfigIsTrue() throws Exception {
    Field field = classWhenConfigIsTrue.getDeclaredField("customFormatDefaultTZ");
    JsonFormat annotation = field.getAnnotation(JsonFormat.class);
    assertThat(annotation, notNullValue());
    // Assert that the patterns match
    assertEquals("yyyy-MM-dd'T'HH:mm:ss", annotation.pattern());
    // Assert that the timezones match
    assertEquals("UTC", annotation.timezone());
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setTimeZone(TimeZone.getTimeZone("UTC"));
    ObjectNode node = objectMapper.createObjectNode();
    node.put("customFormatDefaultTZ", "2016-11-06T00:00:00");
    Object pojo = objectMapper.treeToValue(node, classWhenConfigIsTrue);
    Method getter = new PropertyDescriptor("customFormatDefaultTZ", classWhenConfigIsTrue).getReadMethod();
    // Assert that the Date object in the deserialized class is as expected
    assertEquals(dateTimeFormatter.parse("2016-11-06T00:00:00").toString(), getter.invoke(pojo).toString());
    JsonNode jsonVersion = objectMapper.valueToTree(pojo);
    // Assert that when the class is serialized, the date object is serialized as expected 
    assertEquals("2016-11-06T00:00:00", jsonVersion.get("customFormatDefaultTZ").asText());
}
Also used : Field(java.lang.reflect.Field) JsonFormat(com.fasterxml.jackson.annotation.JsonFormat) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PropertyDescriptor(java.beans.PropertyDescriptor) JsonNode(com.fasterxml.jackson.databind.JsonNode) Method(java.lang.reflect.Method) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 43 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode 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 44 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode 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 45 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode 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)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)767 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)185 JsonNode (com.fasterxml.jackson.databind.JsonNode)165 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)165 Test (org.junit.Test)112 StringEntity (org.apache.http.entity.StringEntity)88 Deployment (org.activiti.engine.test.Deployment)84 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)67 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)64 Task (org.activiti.engine.task.Task)49 HttpPost (org.apache.http.client.methods.HttpPost)49 JCodeModel (com.sun.codemodel.JCodeModel)45 JPackage (com.sun.codemodel.JPackage)44 IOException (java.io.IOException)43 HttpPut (org.apache.http.client.methods.HttpPut)40 JType (com.sun.codemodel.JType)39 HashMap (java.util.HashMap)39 Cluster (org.apache.geode.tools.pulse.internal.data.Cluster)39 ArrayList (java.util.ArrayList)32 Map (java.util.Map)32