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();
}
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());
}
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();
}
}
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);
}
}
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);
}
}
Aggregations