Search in sources :

Example 1 with MismatchedInputException

use of com.fasterxml.jackson.databind.exc.MismatchedInputException in project cassandra by apache.

the class SSTableExportSchemaLoadingTest method testJSONLineArg.

@Test
@SuppressWarnings({ "rawtypes", "DynamicRegexReplaceableByCompiledPattern" })
public void testJSONLineArg() throws IOException {
    ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-l");
    try {
        mapper.readValue(tool.getStdout(), jacksonListOfMapsType);
        fail("Shouldn't be able to deserialize that output, now it's not a collection anymore.");
    } catch (MismatchedInputException e) {
        assertThat(e.getMessage(), startsWith("Cannot deserialize"));
    }
    int parsedCount = 0;
    for (String jsonLine : tool.getStdout().split("\\R")) {
        Map line = mapper.readValue(jsonLine, Map.class);
        assertTrue(jsonLine, line.containsKey("partition"));
        parsedCount++;
    }
    assertEquals(tool.getStdout(), 5, parsedCount);
    assertThat(tool.getStdout(), startsWith("{\""));
    Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
    tool.assertOnExitCode();
    assertPostTestEnv();
}
Also used : MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) Map(java.util.Map) Test(org.junit.Test)

Example 2 with MismatchedInputException

use of com.fasterxml.jackson.databind.exc.MismatchedInputException in project open-kilda by telstra.

the class LoggingFilter method logResponse.

/**
 * Log response.
 *
 * @param response the response
 * @throws JsonParseException the json parse exception
 * @throws JsonMappingException the json mapping exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void logResponse(final ResponseWrapper response) throws JsonParseException, JsonMappingException, IOException {
    StringBuilder msg = new StringBuilder();
    msg.append(RESPONSE_PREFIX);
    msg.append("\nid: '").append((response.getId())).append("' ");
    String content = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        content = new String(response.getData(), response.getCharacterEncoding());
        Object json = mapper.readValue(content, Object.class);
        msg.append("\nResponse: \n").append(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("Log response. Exception: " + e.getMessage(), e);
    } catch (MismatchedInputException e) {
        msg.append("\nResponse: \n").append(content);
    }
    LOGGER.debug("Log response. Response: " + msg.toString());
}
Also used : MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with MismatchedInputException

use of com.fasterxml.jackson.databind.exc.MismatchedInputException in project java-chassis by ServiceComb.

the class TestRestObjectMapper method testJsonObjectWork.

@Test
public void testJsonObjectWork() {
    JsonObject obj = new JsonObject();
    obj.put("name", "a");
    obj.put("desc", "b");
    PojoModel model = RestObjectMapperFactory.getRestObjectMapper().convertValue(obj, TypeFactory.defaultInstance().constructType(PojoModel.class));
    Assert.assertEquals("a", model.getName());
    Assert.assertEquals("b", model.getDesc());
    RestObjectMapperFactory.setDefaultRestObjectMapper(new RestObjectMapper());
    model = RestObjectMapperFactory.getRestObjectMapper().convertValue(obj, TypeFactory.defaultInstance().constructType(PojoModel.class));
    Assert.assertEquals("a", model.getName());
    Assert.assertEquals("b", model.getDesc());
    InputStream inputStream = new ByteArrayInputStream(new byte[0]);
    try {
        RestObjectMapperFactory.getRestObjectMapper().readValue(inputStream, PojoModel.class);
        Assert.fail();
    } catch (MismatchedInputException e) {
    // right place, nothing to do.
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) JsonObject(io.vertx.core.json.JsonObject) RestObjectMapper(org.apache.servicecomb.foundation.common.utils.RestObjectMapper) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) Test(org.junit.Test)

Example 4 with MismatchedInputException

use of com.fasterxml.jackson.databind.exc.MismatchedInputException in project java-chassis by ServiceComb.

the class TestProduceJsonProcessor method testdecodeResponseNull.

@Test
public void testdecodeResponseNull() throws Exception {
    JavaType resultType = TypeFactory.unknownType();
    Object result = pp.decodeResponse(Buffer.buffer(), resultType);
    Assert.assertNull(result);
    ByteArrayInputStream is = new ByteArrayInputStream(new byte[] {});
    try {
        pp.decodeResponse(is, resultType);
        Assert.fail();
    } catch (Exception e) {
        Assert.assertTrue(e instanceof MismatchedInputException);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ByteArrayInputStream(java.io.ByteArrayInputStream) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) Test(org.junit.Test)

Example 5 with MismatchedInputException

use of com.fasterxml.jackson.databind.exc.MismatchedInputException in project trex-stateless-gui by cisco-system-traffic-generator.

the class PortsManager method updatedPorts.

public void updatedPorts(List<Integer> portIndexes) {
    List<Port> list = portList.stream().filter(port -> portIndexes.contains(port.getIndex())).collect(Collectors.toList());
    try {
        String response = ConnectionManager.getInstance().sendPortStatusRequest(list);
        if (response == null) {
            return;
        }
        List<PortStatus> portStatusList = new ArrayList<>();
        try {
            portStatusList = mapper.readValue(response, mapper.getTypeFactory().constructCollectionType(List.class, PortStatus.class));
        } catch (MismatchedInputException ex) {
            portStatusList.add(mapper.readValue(response, mapper.getTypeFactory().constructType(PortStatus.class)));
        }
        for (Port port : list) {
            PortStatus.PortStatusResult portStatus = portStatusList.get(list.indexOf(port)).getResult();
            port.setOwner(portStatus.getOwner());
            port.setStatus(portStatus.getState());
            port.setAttr(portStatus.getAttr());
            port.setRx_info(portStatus.getRx_info());
            port.setService(portStatus.getService());
            port.linkProperty().set(portStatus.getAttr().getLink().getUp());
            updateModel(port.getIndex(), portStatus);
        }
        portManagerHandler.onPortListUpdated(true);
    } catch (Exception ex) {
        logger.error("Error reading port status", ex);
    }
}
Also used : Logger(org.apache.log4j.Logger) java.util(java.util) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) PortModel(com.exalttech.trex.ui.models.PortModel) ConnectionManager(com.exalttech.trex.core.ConnectionManager) PortStatus(com.exalttech.trex.ui.models.PortStatus) Util(com.exalttech.trex.util.Util) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Collectors(java.util.stream.Collectors) Port(com.exalttech.trex.ui.models.Port) PortVlan(com.cisco.trex.stateless.model.port.PortVlan) Port(com.exalttech.trex.ui.models.Port) PortStatus(com.exalttech.trex.ui.models.PortStatus) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException)

Aggregations

MismatchedInputException (com.fasterxml.jackson.databind.exc.MismatchedInputException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Map (java.util.Map)2 SuppressFBWarnings (alluxio.annotation.SuppressFBWarnings)1 PortVlan (com.cisco.trex.stateless.model.port.PortVlan)1 ConnectionManager (com.exalttech.trex.core.ConnectionManager)1 Port (com.exalttech.trex.ui.models.Port)1 PortModel (com.exalttech.trex.ui.models.PortModel)1 PortStatus (com.exalttech.trex.ui.models.PortStatus)1 Util (com.exalttech.trex.util.Util)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonObject (io.vertx.core.json.JsonObject)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 Serializable (java.io.Serializable)1