Search in sources :

Example 1 with RawValue

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue in project jackson-databind by FasterXML.

the class TestJsonNode method testRawValue.

// [databind#743]
public void testRawValue() throws Exception {
    ObjectNode root = MAPPER.createObjectNode();
    root.putRawValue("a", new RawValue(new SerializedString("[1, 2, 3]")));
    assertEquals("{\"a\":[1, 2, 3]}", MAPPER.writeValueAsString(root));
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) RawValue(com.fasterxml.jackson.databind.util.RawValue)

Example 2 with RawValue

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue in project flink by apache.

the class JsonObjectAggFunction method getValue.

@Override
public String getValue(Accumulator acc) {
    final ObjectNode rootNode = createObjectNode();
    try {
        for (final StringData key : acc.map.keys()) {
            final StringData value = acc.map.get(key);
            final JsonNode valueNode = value == null ? NULL_NODE : getNodeFactory().rawValueNode(new RawValue(value.toString()));
            rootNode.set(key.toString(), valueNode);
        }
    } catch (Exception e) {
        throw new TableException("The accumulator state could not be serialized.", e);
    }
    return serializeJson(rootNode);
}
Also used : TableException(org.apache.flink.table.api.TableException) ObjectNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode) SqlJsonUtils.createObjectNode(org.apache.flink.table.runtime.functions.SqlJsonUtils.createObjectNode) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) StringData(org.apache.flink.table.data.StringData) RawValue(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue) TableException(org.apache.flink.table.api.TableException)

Example 3 with RawValue

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue in project jackson-databind by FasterXML.

the class RawValueTest method testRawFromMapToTree.

// for [databind#743]
public void testRawFromMapToTree() throws Exception {
    RawValue myType = new RawValue("Jackson");
    Map<String, Object> object = new HashMap<String, Object>();
    object.put("key", myType);
    JsonNode jsonNode = MAPPER.valueToTree(object);
    String json = MAPPER.writeValueAsString(jsonNode);
    assertEquals("{\"key\":Jackson}", json);
}
Also used : HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) RawValue(com.fasterxml.jackson.databind.util.RawValue)

Example 4 with RawValue

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue in project flink by apache.

the class JsonArrayAggFunction method getValue.

@Override
public String getValue(Accumulator acc) {
    final ArrayNode rootNode = createArrayNode();
    try {
        for (final StringData item : acc.list.get()) {
            final JsonNode itemNode = getNodeFactory().rawValueNode(new RawValue(item.toString()));
            rootNode.add(itemNode);
        }
    } catch (Exception e) {
        throw new TableException("The accumulator state could not be serialized.", e);
    }
    return serializeJson(rootNode);
}
Also used : TableException(org.apache.flink.table.api.TableException) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) SqlJsonUtils.createArrayNode(org.apache.flink.table.runtime.functions.SqlJsonUtils.createArrayNode) ArrayNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode) StringData(org.apache.flink.table.data.StringData) RawValue(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue) TableException(org.apache.flink.table.api.TableException)

Aggregations

RawValue (com.fasterxml.jackson.databind.util.RawValue)2 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)2 RawValue (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue)2 TableException (org.apache.flink.table.api.TableException)2 StringData (org.apache.flink.table.data.StringData)2 SerializedString (com.fasterxml.jackson.core.io.SerializedString)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HashMap (java.util.HashMap)1 ArrayNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode)1 SqlJsonUtils.createArrayNode (org.apache.flink.table.runtime.functions.SqlJsonUtils.createArrayNode)1 SqlJsonUtils.createObjectNode (org.apache.flink.table.runtime.functions.SqlJsonUtils.createObjectNode)1