List of usage examples for com.fasterxml.jackson.databind JsonMappingException JsonMappingException
public JsonMappingException(String paramString)
From source file:org.jboss.aerogear.io.netty.handler.codec.sockjs.util.JsonUtil.java
public static String[] decode(final String content) throws IOException { final JsonNode root = MAPPER.readTree(content); if (root.isObject()) { return new String[] { root.toString() }; }// w w w. j a va2 s.c o m if (root.isValueNode()) { return new String[] { root.asText() }; } if (!root.isArray()) { throw new JsonMappingException("content must be a JSON Array but was : " + content); } final List<String> messages = new ArrayList<String>(); final Iterator<JsonNode> elements = root.elements(); while (elements.hasNext()) { final JsonNode field = elements.next(); if (field.isValueNode()) { messages.add(field.asText()); } else { messages.add(field.toString()); } } return messages.toArray(new String[messages.size()]); }
From source file:com.servioticy.datamodel.serviceobject.SO.java
@JsonSetter("streams") protected void setCheckStreams(LinkedHashMap<String, Object> streams) throws IOException { if (streams == null || streams.size() < 1) { throw new JsonMappingException("At least one stream is required"); }//from ww w . ja v a 2 s .c om this.streamsRaw = streams; }
From source file:org.jboss.aerogear.io.netty.handler.codec.sockjs.util.JsonUtil.java
public static String encode(final String content) throws JsonMappingException { try {//from w w w . ja va 2 s. c o m return MAPPER.writeValueAsString(content); } catch (Exception e) { throw new JsonMappingException("content must be a JSON Array but was : " + content); } }
From source file:com.github.tomakehurst.wiremock.matching.StringValuePatternJsonDeserializer.java
private static Class<? extends StringValuePattern> findPatternClass(JsonNode rootNode) throws JsonMappingException { for (Map.Entry<String, JsonNode> node : ImmutableList.copyOf(rootNode.fields())) { Class<? extends StringValuePattern> patternClass = PATTERNS.get(node.getKey()); if (patternClass != null) { return patternClass; }/*from w w w. ja v a 2 s.com*/ } throw new JsonMappingException(rootNode.toString() + " is not a valid comparison"); }
From source file:org.venice.piazza.servicecontroller.taskmanaged.TaskManagedTests.java
/** * Tests logic for pulling a Job off the queue for a service *//*from www . ja va2 s. co m*/ @Test public void testGetJob() throws ResourceAccessException, InterruptedException, InvalidInputException, JsonProcessingException { // Mock ServiceJob mockServiceJob = new ServiceJob("job123", "service123"); Mockito.when(mongoAccessor.getNextJobInServiceQueue(Mockito.eq("service123"))).thenReturn(mockServiceJob); // Test - normal flow, proper Job type Job mockJob = new Job(); mockJob.setJobId("job123"); mockJob.setJobType(new ExecuteServiceJob("job123")); Mockito.when(mongoAccessor.getJobById(Mockito.eq("job123"))).thenReturn(mockJob); ExecuteServiceJob result = serviceTaskManager.getNextJobFromQueue("service123"); // Check not null, and proper Job ID Assert.isInstanceOf(ExecuteServiceJob.class, result); Assert.isTrue(result.getJobId().equals("job123")); // Test - Handle Kafka Exception Mockito.when(objectMapper.writeValueAsString(Mockito.any())).thenThrow(new JsonMappingException("Oops")); result = serviceTaskManager.getNextJobFromQueue("service123"); // Check not null, and proper Job ID Assert.isInstanceOf(ExecuteServiceJob.class, result); Assert.isTrue(result.getJobId().equals("job123")); }
From source file:com.arpnetworking.metrics.impl.TsdQueryLogSinkTest.java
@Test public void testObjectMapperIOException() throws IOException { final org.slf4j.Logger logger = createSlf4jLoggerMock(); final ObjectMapper objectMapper = Mockito.mock(ObjectMapper.class); final Sink sink = new TsdQueryLogSink(new TsdQueryLogSink.Builder().setPath("./target/TsdQueryLogSinkTest") .setName("testObjectMapperIOException-Query"), objectMapper, logger); Mockito.doThrow(new JsonMappingException("JsonMappingException")).when(objectMapper) .writeValueAsString(Mockito.any()); recordEmpty(sink);/*from ww w.ja v a 2s . c o m*/ Mockito.verify(logger).warn(Mockito.argThat(Matchers.any(String.class)), Mockito.argThat(Matchers.any(Throwable.class))); }
From source file:org.venice.piazza.servicecontroller.taskmanaged.TaskManagedTests.java
/** * Tests getting a Job off the queue that has an improper type */// w ww . j a v a 2s.c o m @Test(expected = InvalidInputException.class) public void testGetJobTypeError() throws ResourceAccessException, InterruptedException, JsonProcessingException, InvalidInputException { // Mock ServiceJob mockServiceJob = new ServiceJob("job123", "service123"); Mockito.when(mongoAccessor.getNextJobInServiceQueue(Mockito.eq("service123"))).thenReturn(mockServiceJob); // Test - Handle Kafka Exception, with Improper Job Type Job mockJob = new Job(); mockJob.setJobId("job123"); mockJob.setJobType(new AbortJob("job321")); Mockito.when(mongoAccessor.getJobById(Mockito.eq("job123"))).thenReturn(mockJob); Mockito.when(objectMapper.writeValueAsString(Mockito.any())).thenThrow(new JsonMappingException("Oops")); serviceTaskManager.getNextJobFromQueue("service123"); // Should throw }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.ListServiceHandlerTest.java
/** * Test that the list of services could not be retrieved * due to a marshalling error//from w ww .j ava2 s. c o m */ @Test public void testUnsuccessListServiceException() { ResponseEntity<String> responseEntity = new ResponseEntity<String>( "Could not retrieve a list of user services", HttpStatus.NOT_FOUND); try { final ListServiceHandler lsMock = Mockito.spy(lsHandler); Mockito.doReturn(omMock).when(lsMock).makeObjectMapper(); Mockito.doReturn(services).when(accessorMock).list(); Mockito.when(omMock.writeValueAsString(services)).thenThrow(new JsonMappingException("Test Exception")); ResponseEntity<String> result = lsMock.handle(); assertEquals("The response entity was correct for this list service request", responseEntity, result); assertEquals("The response code is 404", responseEntity.getStatusCode(), HttpStatus.NOT_FOUND); assertEquals("The body of the response is correct", responseEntity.getBody(), "Could not retrieve a list of user services"); } catch (JsonProcessingException jpe) { jpe.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.SearchServiceHandlerTest.java
/** * Test that the results throws a JSON exception * due to a marshalling error// w w w. j a v a2 s . c o m */ @Test public void testThrowException() { ResponseEntity<String> responseEntity = new ResponseEntity<String>("Could not search for services", HttpStatus.NOT_FOUND); SearchCriteria criteria = new SearchCriteria(); criteria.field = "animalType"; criteria.pattern = "A*r"; try { final SearchServiceHandler ssMock = Mockito.spy(ssHandler); Mockito.doReturn(omMock).when(ssMock).makeObjectMapper(); Mockito.doReturn(services).when(accessorMock).search(criteria); Mockito.when(omMock.writeValueAsString(services)).thenThrow(new JsonMappingException("Test Exception")); ResponseEntity<String> result = ssMock.handle(criteria); assertEquals("The response entity was correct for the search request", responseEntity, result); assertEquals("The response code is 404", responseEntity.getStatusCode(), HttpStatus.NOT_FOUND); assertEquals("The body of the response is correct", responseEntity.getBody(), "Could not search for services"); } catch (JsonProcessingException jpe) { jpe.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.ExecuteServiceHandlerTest.java
/** * Test that the results throws a JSON exception * due to a marshalling error/*from www . j ava 2 s. c o m*/ */ @Test public void testThrowException() { ExecuteServiceData edata = new ExecuteServiceData(); String serviceId = "8"; edata.setServiceId(serviceId); HashMap<String, DataType> dataInputs = new HashMap<String, DataType>(); TextDataType tdt = new TextDataType(); tdt.content = "Marge"; dataInputs.put("name", tdt); edata.setDataInputs(dataInputs); URI uri = URI.create("http://localhost:8082/string/toUpper"); try { final ExecuteServiceHandler esMock = Mockito.spy(executeServiceHandler); // Now create the serialized objects to test against Map<String, DataType> postObjects = new HashMap<>(); postObjects.put("name", tdt); Mockito.when(serviceMock.getUrl()).thenReturn(uri.toString()); Mockito.when(accessorMock.getServiceById("8")).thenReturn(service); Mockito.doReturn(omMock).when(esMock).makeObjectMapper(); Mockito.when(omMock.writeValueAsString(postObjects)) .thenThrow(new JsonMappingException("Test Exception")); ResponseEntity<String> retVal = esMock.handle(edata); assertEquals("The response code is 400 for BAD_REQUEST", retVal.getStatusCode(), HttpStatus.BAD_REQUEST); } catch (JsonProcessingException jpe) { jpe.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }