Search in sources :

Example 71 with TextNode

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

the class CommandDeserializer method toCommand.

private List<String> toCommand(ArrayNode arrayCommandNode, DeserializationContext ctxt) throws JsonMappingException {
    List<String> commands = new ArrayList<>();
    for (TreeNode treeNode : arrayCommandNode) {
        if (treeNode instanceof TextNode) {
            TextNode textNode = (TextNode) treeNode;
            commands.add(textNode.asText());
        } else {
            throw ctxt.mappingException("Array 'command' contains not string element.");
        }
    }
    return commands;
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) ArrayList(java.util.ArrayList) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 72 with TextNode

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

the class TestTreeTraversingParser method testTextAsBinary.

public void testTextAsBinary() throws Exception {
    TextNode n = new TextNode("   APs=\n");
    JsonParser p = n.traverse();
    assertNull(p.getCurrentToken());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    byte[] data = p.getBinaryValue();
    assertNotNull(data);
    assertArrayEquals(new byte[] { 0, -5 }, data);
    assertNull(p.nextToken());
    p.close();
    assertTrue(p.isClosed());
    // Also: let's verify we get an exception for garbage...
    n = new TextNode("?!??");
    p = n.traverse();
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    try {
        p.getBinaryValue();
    } catch (InvalidFormatException e) {
        verifyException(e, "Illegal character");
    }
    p.close();
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) InvalidFormatException(com.fasterxml.jackson.databind.exc.InvalidFormatException)

Example 73 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class InfoArchiveRestClient method getValidJsonRequestForExport.

private String getValidJsonRequestForExport(String exportConfigurationUri, List<SearchResult> searchResults) {
    JsonNodeFactory jsonNodeFactory = new ObjectMapper().getNodeFactory();
    ObjectNode root = jsonNodeFactory.objectNode();
    ArrayNode includedRows = jsonNodeFactory.arrayNode();
    for (SearchResult searchResult : searchResults) {
        for (Row row : searchResult.getRows()) {
            includedRows.add(row.getId());
        }
    }
    TextNode exportConfiguration = jsonNodeFactory.textNode(exportConfigurationUri);
    root.set("exportConfiguration", exportConfiguration);
    root.set("includedRows", includedRows);
    return root.toString();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 74 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project parquet-mr by apache.

the class AvroJson method visit.

private static <T> T visit(JsonNode node, JsonTreeVisitor<T> visitor) {
    switch(node.getNodeType()) {
        case OBJECT:
            Preconditions.checkArgument(node instanceof ObjectNode, "Expected instance of ObjectNode: " + node);
            // use LinkedHashMap to preserve field order
            Map<String, T> fields = Maps.newLinkedHashMap();
            Iterator<Map.Entry<String, JsonNode>> iter = node.fields();
            while (iter.hasNext()) {
                Map.Entry<String, JsonNode> entry = iter.next();
                visitor.recordLevels.push(entry.getKey());
                fields.put(entry.getKey(), visit(entry.getValue(), visitor));
                visitor.recordLevels.pop();
            }
            return visitor.object((ObjectNode) node, fields);
        case ARRAY:
            Preconditions.checkArgument(node instanceof ArrayNode, "Expected instance of ArrayNode: " + node);
            List<T> elements = Lists.newArrayListWithExpectedSize(node.size());
            for (JsonNode element : node) {
                elements.add(visit(element, visitor));
            }
            return visitor.array((ArrayNode) node, elements);
        case BINARY:
            Preconditions.checkArgument(node instanceof BinaryNode, "Expected instance of BinaryNode: " + node);
            return visitor.binary((BinaryNode) node);
        case STRING:
            Preconditions.checkArgument(node instanceof TextNode, "Expected instance of TextNode: " + node);
            return visitor.text((TextNode) node);
        case NUMBER:
            Preconditions.checkArgument(node instanceof NumericNode, "Expected instance of NumericNode: " + node);
            return visitor.number((NumericNode) node);
        case BOOLEAN:
            Preconditions.checkArgument(node instanceof BooleanNode, "Expected instance of BooleanNode: " + node);
            return visitor.bool((BooleanNode) node);
        case MISSING:
            Preconditions.checkArgument(node instanceof MissingNode, "Expected instance of MissingNode: " + node);
            return visitor.missing((MissingNode) node);
        case NULL:
            Preconditions.checkArgument(node instanceof NullNode, "Expected instance of NullNode: " + node);
            return visitor.nullNode((NullNode) node);
        default:
            throw new IllegalArgumentException("Unknown node type: " + node.getNodeType() + ": " + node);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) BinaryNode(com.fasterxml.jackson.databind.node.BinaryNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NullNode(com.fasterxml.jackson.databind.node.NullNode)

Example 75 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project solr-document-store by DBCDK.

the class StatusBean method createDiagStatusNode.

private JsonNode createDiagStatusNode() {
    try (Connection connection = dataSource.getConnection();
        Statement stmt = connection.createStatement();
        ResultSet resultSet = stmt.executeQuery("SELECT diag FROM queue_error")) {
        ObjectNode node = O.createObjectNode();
        HashMap<ArrayList<String>, AtomicInteger> diags = new HashMap<>();
        int c = 0;
        while (resultSet.next() && c++ <= DIAG_COLLAPSE_MAX_ROWS) {
            addToDiags(diags, resultSet.getString(1));
        }
        if (c > DIAG_COLLAPSE_MAX_ROWS) {
            node.put("", "Diags limited to " + DIAG_COLLAPSE_MAX_ROWS + " rows");
        }
        Map<ArrayList<String>, String> sortKey = diags.keySet().stream().collect(Collectors.toMap(a -> a, a -> diagAsString(a)));
        diags.entrySet().stream().sorted((l, r) -> sortKey.get(l.getKey()).compareToIgnoreCase(sortKey.get(r.getKey()))).forEach(e -> {
            node.put(sortKey.get(e.getKey()), e.getValue().get());
        });
        return node;
    } catch (SQLException ex) {
        log.error("Sql error counting queue entries: {}", ex.getMessage());
        log.debug("Sql error counting queue entries: ", ex);
        return new TextNode("SQL Exception");
    }
}
Also used : Arrays(java.util.Arrays) Connection(java.sql.Connection) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Timed(dk.dbc.search.solrdocstore.monitor.Timed) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SQLException(java.sql.SQLException) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) ManagedExecutorService(javax.enterprise.concurrent.ManagedExecutorService) QueryParam(javax.ws.rs.QueryParam) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) Map(java.util.Map) DataSource(javax.sql.DataSource) DefaultValue(javax.ws.rs.DefaultValue) JsonNode(com.fasterxml.jackson.databind.JsonNode) ExecutorService(java.util.concurrent.ExecutorService) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Resource(javax.annotation.Resource) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) PreparedStatement(java.sql.PreparedStatement) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) TextNode(com.fasterxml.jackson.databind.node.TextNode) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Response(javax.ws.rs.core.Response) Statement(java.sql.Statement) Collections(java.util.Collections) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) TextNode(com.fasterxml.jackson.databind.node.TextNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet)

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