Search in sources :

Example 86 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.

the class BaseExpressionEvaluatorTest method expressionMapVerifyResultTest.

@Test(expected = IllegalArgumentException.class)
public void expressionMapVerifyResultTest() {
    String expressionCollectionJsonString = new TextNode("{key_a : 1}").toString();
    Map<String, BigDecimal> contextValue = Collections.singletonMap("key_a", BigDecimal.valueOf(1));
    assertTrue(expressionEvaluator.verifyResult(expressionCollectionJsonString, contextValue, Map.class).isSuccessful());
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 87 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.

the class DMNFeelExpressionEvaluatorTest method expressionObjectListTest.

@Test
public void expressionObjectListTest() {
    String expressionCollectionJsonString = new TextNode("[{age:10},{name:\"John\"}]").toString();
    List<Map<String, Object>> result = (List<Map<String, Object>>) expressionEvaluator.convertResult(expressionCollectionJsonString, List.class.getCanonicalName(), Collections.EMPTY_LIST);
    assertEquals(2, result.size());
    assertThat(result.get(0)).containsOnly(entry("age", BigDecimal.TEN));
    assertThat(result.get(1)).containsOnly(entry("name", "John"));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 88 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.

the class DMNFeelExpressionEvaluatorTest method expressionListVerifyResultTest.

@Test
public void expressionListVerifyResultTest() {
    String expressionCollectionJsonString = new TextNode("10").toString();
    List<BigDecimal> contextValue = Collections.singletonList(BigDecimal.valueOf(10));
    assertTrue(expressionEvaluator.verifyResult(expressionCollectionJsonString, contextValue, List.class).isSuccessful());
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 89 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.

the class DMNFeelExpressionEvaluatorTest method expressionMapVerifyResultTest.

@Test
public void expressionMapVerifyResultTest() {
    String expressionCollectionJsonString = new TextNode("{key_a : 1}").toString();
    Map<String, BigDecimal> contextValue = Collections.singletonMap("key_a", BigDecimal.valueOf(1));
    assertTrue(expressionEvaluator.verifyResult(expressionCollectionJsonString, contextValue, Map.class).isSuccessful());
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 90 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.

the class Node method iterateObject.

/**
 * Iterate over a Jackson object and create a Java Map.
 *
 * @param node.
 *            ObjectNode. The Jackson node to set up as a Map.
 * @return Map. Returns the Map implementation of the Jackson node.
 */
Map iterateObject(ObjectNode node) {
    Map m = new HashMap();
    Iterator it = node.iterator();
    it = node.fieldNames();
    while (it.hasNext()) {
        String key = (String) it.next();
        Object s = node.get(key);
        if (s instanceof TextNode) {
            TextNode t = (TextNode) s;
            m.put(key, t.textValue());
        } else if (s instanceof DoubleNode) {
            DoubleNode t = (DoubleNode) s;
            m.put(key, t.numberValue());
        } else if (s instanceof IntNode) {
            IntNode t = (IntNode) s;
            m.put(key, t.numberValue());
        } else
            // indeterminate, need to traverse
            m.put(key, s);
    }
    return m;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Iterator(java.util.Iterator) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NavMap(com.xrtb.blocks.NavMap)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)140 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)48 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)37 Test (org.junit.Test)37 JsonNode (com.fasterxml.jackson.databind.JsonNode)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 IntNode (com.fasterxml.jackson.databind.node.IntNode)16 ArrayList (java.util.ArrayList)16 Test (org.junit.jupiter.api.Test)15 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)12 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 TreeNode (com.fasterxml.jackson.core.TreeNode)11 HashMap (java.util.HashMap)11 List (java.util.List)11 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 Map (java.util.Map)10