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();
}
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());
}
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());
}
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);
}
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());
}
Aggregations