Search in sources :

Example 61 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project jackson-databind by FasterXML.

the class ObjectReaderTest method testCodecUnsupportedWrites.

public void testCodecUnsupportedWrites() throws Exception {
    ObjectReader r = MAPPER.readerFor(String.class);
    JsonGenerator g = MAPPER.getFactory().createGenerator(new StringWriter());
    ObjectNode n = MAPPER.createObjectNode();
    try {
        r.writeTree(g, n);
        fail("Should not pass");
    } catch (UnsupportedOperationException e) {
        ;
    }
    try {
        r.writeValue(g, "Foo");
        fail("Should not pass");
    } catch (UnsupportedOperationException e) {
        ;
    }
    g.close();
    g.close();
}
Also used : StringWriter(java.io.StringWriter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 62 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project jackson-databind by FasterXML.

the class NodeMergeTest method testObjectNodeUpdateValue.

/*
    /********************************************************
    /* Test methods
    /********************************************************
     */
public void testObjectNodeUpdateValue() throws Exception {
    ObjectNode base = MAPPER.createObjectNode();
    base.put("first", "foo");
    assertSame(base, MAPPER.readerForUpdating(base).readValue(aposToQuotes("{'second':'bar', 'third':5, 'fourth':true}")));
    assertEquals(4, base.size());
    assertEquals("bar", base.path("second").asText());
    assertEquals("foo", base.path("first").asText());
    assertEquals(5, base.path("third").asInt());
    assertTrue(base.path("fourth").asBoolean());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 63 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project jackson-databind by FasterXML.

the class NodeMergeTest method testObjectDeepUpdate.

public void testObjectDeepUpdate() throws Exception {
    ObjectNode base = MAPPER.createObjectNode();
    ObjectNode props = base.putObject("props");
    props.put("base", 123);
    props.put("value", 456);
    ArrayNode a = props.putArray("array");
    a.add(true);
    base.putNull("misc");
    assertSame(base, MAPPER.readerForUpdating(base).readValue(aposToQuotes("{'props':{'value':true, 'extra':25.5, 'array' : [ 3 ]}}")));
    assertEquals(2, base.size());
    ObjectNode resultProps = (ObjectNode) base.get("props");
    assertEquals(4, resultProps.size());
    assertEquals(123, resultProps.path("base").asInt());
    assertTrue(resultProps.path("value").asBoolean());
    assertEquals(25.5, resultProps.path("extra").asDouble());
    JsonNode n = resultProps.get("array");
    assertEquals(ArrayNode.class, n.getClass());
    assertEquals(2, n.size());
    assertEquals(3, n.get(1).asInt());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 64 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project jackson-databind by FasterXML.

the class TestBeanConversions method testNodeConvert.

// [Issue-11]: simple cast, for Tree
public void testNodeConvert() throws Exception {
    ObjectNode src = (ObjectNode) MAPPER.readTree("{}");
    TreeNode node = src;
    ObjectNode result = MAPPER.treeToValue(node, ObjectNode.class);
    // should just cast...
    assertSame(src, result);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TreeNode(com.fasterxml.jackson.core.TreeNode)

Example 65 with ObjectNode

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

the class HistoryServiceTest method testLocalizeTasks.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testLocalizeTasks() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()).list();
    assertEquals(1, tasks.size());
    assertEquals("my task", tasks.get(0).getName());
    assertNull(tasks.get(0).getDescription());
    ObjectNode infoNode = dynamicBpmnService.changeLocalizationName("en-GB", "theTask", "My localized name");
    dynamicBpmnService.changeLocalizationDescription("en-GB".toString(), "theTask", "My localized description", infoNode);
    dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);
    tasks = historyService.createHistoricTaskInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()).list();
    assertEquals(1, tasks.size());
    assertEquals("my task", tasks.get(0).getName());
    assertNull(tasks.get(0).getDescription());
    tasks = historyService.createHistoricTaskInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()).locale("en-GB").list();
    assertEquals(1, tasks.size());
    assertEquals("My localized name", tasks.get(0).getName());
    assertEquals("My localized description", tasks.get(0).getDescription());
    tasks = historyService.createHistoricTaskInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()).listPage(0, 10);
    assertEquals(1, tasks.size());
    assertEquals("my task", tasks.get(0).getName());
    assertNull(tasks.get(0).getDescription());
    tasks = historyService.createHistoricTaskInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()).locale("en-GB").listPage(0, 10);
    assertEquals(1, tasks.size());
    assertEquals("My localized name", tasks.get(0).getName());
    assertEquals("My localized description", tasks.get(0).getDescription());
    HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
    assertEquals("my task", task.getName());
    assertNull(task.getDescription());
    task = historyService.createHistoricTaskInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()).locale("en-GB").singleResult();
    assertEquals("My localized name", task.getName());
    assertEquals("My localized description", task.getDescription());
    task = historyService.createHistoricTaskInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
    assertEquals("my task", task.getName());
    assertNull(task.getDescription());
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)769 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)185 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)167 JsonNode (com.fasterxml.jackson.databind.JsonNode)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)44 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 Map (java.util.Map)33 ArrayList (java.util.ArrayList)32