Search in sources :

Example 56 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project JMRI by JMRI.

the class JsonClientTrafficController method receiveLoop.

@Override
public void receiveLoop() {
    log.debug("receiveLoop starts");
    ObjectReader reader = this.mapper.reader();
    while (true) {
        try {
            JsonNode root = reader.readTree((InputStream) this.istream);
            String type = root.path(TYPE).asText();
            JsonNode data = root.path(DATA);
            log.debug("Processing {} with {}", type, data);
            if (type.equals(GOODBYE)) {
                log.info("Connection closing from server.");
                break;
            } else if (type.equals(HELLO)) {
                this.receiveHello(data);
            } else if (type.equals(LOCALE)) {
                this.receiveHello(data);
            } else if (type.equals(PONG)) {
            // silently ignore
            } else if (!data.isMissingNode() || (root.isArray() && ((ArrayNode) root).size() > 0)) {
                // process replies with a data node or non-empty arrays
                JsonClientReply reply = new JsonClientReply(root);
                Runnable r = new RcvNotifier(reply, mLastSender, this);
                try {
                    SwingUtilities.invokeAndWait(r);
                } catch (InterruptedException e) {
                    log.error("Exception notifying listeners of reply: {}", e.getMessage(), e);
                } catch (InvocationTargetException e) {
                    log.error("Exception notifying listeners of reply: {}", e.getMessage(), e);
                }
            }
        } catch (IOException e) {
            this.rcvException = true;
            reportReceiveLoopException(e);
            break;
        } catch (NoSuchElementException nse) {
            // so break out of the loop
            break;
        }
    }
    ConnectionStatus.instance().setConnectionState(this.controller.getCurrentPortName(), ConnectionStatus.CONNECTION_DOWN);
    log.error("Exit from rcv loop");
    this.recovery();
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchElementException(java.util.NoSuchElementException)

Example 57 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project knime-core by knime.

the class AbstractPageManager method getJSONLayoutFromSubnode.

private JSONLayoutPage getJSONLayoutFromSubnode(final NodeIDSuffix pageID, final String layoutInfo) throws IOException {
    ObjectMapper mapper = JSONLayoutPage.getConfiguredVerboseObjectMapper();
    ObjectReader reader = mapper.readerForUpdating(new JSONLayoutPage());
    JSONLayoutPage page = reader.readValue(layoutInfo);
    if (page != null && page.getRows() != null) {
        for (JSONLayoutRow row : page.getRows()) {
            setNodeIDInContent(row, pageID);
        }
    }
    return page;
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) JSONLayoutRow(org.knime.js.core.layout.bs.JSONLayoutRow) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 58 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method getJsonDocument.

/**
 * @return the jsonDocument
 */
public String getJsonDocument() {
    ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
    ObjectReader reader = mapper.readerForUpdating(new JSONLayoutPage());
    try {
        String json = isWindows() ? m_textArea.getText() : m_jsonDocument;
        JSONLayoutPage page = reader.readValue(json);
        String layoutString = mapper.writeValueAsString(page);
        return layoutString;
    } catch (IOException e) {
        LOGGER.error("Failed to retrieve JSON string from layout:" + e.getMessage(), e);
    }
    return "";
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 59 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method updateBasicLayout.

private void updateBasicLayout() {
    ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
    JSONLayoutPage page = new JSONLayoutPage();
    ObjectReader reader = mapper.readerForUpdating(page);
    try {
        page = reader.readValue(m_jsonDocument);
    } catch (Exception e) {
    /* do nothing, input needs to be validated beforehand */
    }
    m_basicMap.clear();
    m_basicPanelAvailable = true;
    List<JSONLayoutRow> rows = page.getRows();
    for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
        JSONLayoutRow row = rows.get(rowIndex);
        populateDocumentNodeIDs(row);
        processBasicLayoutRow(row, rowIndex);
    }
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) JSONLayoutRow(org.knime.js.core.layout.bs.JSONLayoutRow) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Point(org.eclipse.swt.graphics.Point)

Example 60 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project drill by axbaretto.

the class TestParsePhysicalPlan method parseSimplePlan.

@Test
public void parseSimplePlan() throws Exception {
    DrillConfig c = DrillConfig.create();
    ScanResult scanResult = ClassPathScanner.fromPrescan(c);
    LogicalPlanPersistence lpp = new LogicalPlanPersistence(c, scanResult);
    PhysicalPlanReader reader = new PhysicalPlanReader(c, scanResult, lpp, CoordinationProtos.DrillbitEndpoint.getDefaultInstance(), null);
    ObjectReader r = lpp.getMapper().reader(PhysicalPlan.class);
    ObjectWriter writer = lpp.getMapper().writer();
    PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/physical_test1.json"), Charsets.UTF_8));
    String unparse = plan.unparse(writer);
// System.out.println(unparse);
}
Also used : ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) DrillConfig(org.apache.drill.common.config.DrillConfig) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) LogicalPlanPersistence(org.apache.drill.common.config.LogicalPlanPersistence) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest) PlannerTest(org.apache.drill.categories.PlannerTest)

Aggregations

ObjectReader (com.fasterxml.jackson.databind.ObjectReader)82 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 IOException (java.io.IOException)32 Test (org.junit.Test)23 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ArrayList (java.util.ArrayList)8 JavaType (com.fasterxml.jackson.databind.JavaType)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)6 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)5 Map (java.util.Map)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)4 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)4 Method (java.lang.reflect.Method)4 List (java.util.List)4 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)3 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)3 JSONLayoutPage (org.knime.js.core.layout.bs.JSONLayoutPage)3