List of usage examples for com.fasterxml.jackson.databind JsonMappingException JsonMappingException
public JsonMappingException(String paramString)
From source file:com.evrythng.java.wrapper.mapping.CreateActionsJobInputDeserializer.java
@Override public CreateActionJob.Input deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode typeNode = node.get(CreateActionJob.Input.FIELD_TYPE); if (typeNode == null) { throw new JsonMappingException("Cannot deserialize create actions job input without type field"); }/* w ww . j ava 2s. com*/ String typeRaw = getFieldValue(typeNode); JsonNode contentTypeNode = node.get(CreateActionJob.Input.FIELD_CONTENT_TYPE); if (contentTypeNode == null) { throw new JsonMappingException("Cannot deserialize create actions job input without contentType field"); } String contentTypeRaw = getFieldValue(contentTypeNode); Class<? extends CreateActionJob.Input> subtypeClass = classForType( CreateActionJob.Input.Type.valueOf(typeRaw.toUpperCase()), CreateActionJob.Input.ContentType.valueOf(contentTypeRaw.toUpperCase())); return mapper.readValue(node.toString(), subtypeClass); }
From source file:org.mongojack.internal.ObjectIdSerializer.java
private Object serialiseObject(Object value) throws JsonMappingException { if (value == null) { return null; } else if (value instanceof String) { return new ObjectId((String) value); } else if (value instanceof byte[]) { return new ObjectId((byte[]) value); } else if (value instanceof DBRef) { DBRef dbRef = (DBRef) value;//from w w w . ja va 2 s. com Object id = serialiseObject(dbRef.getId()); if (id == null) { return null; } return new com.mongodb.DBRef(null, dbRef.getCollectionName(), id); } else if (value instanceof ObjectId) { return value; } else { throw new JsonMappingException( "Cannot deserialise object of type " + value.getClass() + " to ObjectId"); } }
From source file:org.venice.piazza.servicecontroller.taskmanaged.TaskManagedTests.java
/** * Tests adding a job to a Service's queue. *//*ww w . j ava2s.c o m*/ @Test public void testAddJob() throws JsonProcessingException { // Mock Data ExecuteServiceJob job = new ExecuteServiceJob("job123"); job.setData(new ExecuteServiceData()); job.getData().setServiceId("service123"); // Test, ensure no errors serviceTaskManager.addJobToQueue(job); // Test Exception handling, ensure exception is handled Mockito.when(objectMapper.writeValueAsString(Mockito.any())).thenThrow(new JsonMappingException("Oops")); }
From source file:com.servioticy.datamodel.sensorupdate.SensorUpdate.java
@JsonSetter("channels") public void setNotNullOrEmptyChannels(LinkedHashMap<String, SUChannel> channels) throws JsonMappingException { if (channels == null || channels.size() < 1) { throw new JsonMappingException("At least one channel is required"); }/*from ww w. j a v a 2s . c o m*/ setChannels(channels); }
From source file:org.wikidata.wdtk.datamodel.json.jackson.datavalues.JacksonValueDeserializer.java
/** * Finds the Java class to use for deserializing the JSON structure * represented by the given node.//from ww w .j a v a 2 s.c o m * * @param jsonNode * the JSON node that represents the value to deserialize * @return the Java class to use for deserialization * @throws JsonMappingException * if we do not have a class for the given JSON */ private Class<? extends JacksonValue> getValueClass(JsonNode jsonNode) throws JsonMappingException { String jsonType = jsonNode.get("type").asText(); switch (jsonType) { case JacksonValue.JSON_VALUE_TYPE_ENTITY_ID: JsonNode valueNode = jsonNode.get("value"); if (valueNode != null) { String entityType = valueNode.get("entity-type").asText(); switch (entityType) { case JacksonInnerEntityId.JSON_ENTITY_TYPE_ITEM: return JacksonValueItemId.class; case JacksonInnerEntityId.JSON_ENTITY_TYPE_PROPERTY: return JacksonValuePropertyId.class; default: throw new JsonMappingException( "Entities of type \"" + entityType + "\" are not supported as property values yet."); } } case JacksonValue.JSON_VALUE_TYPE_STRING: return JacksonValueString.class; case JacksonValue.JSON_VALUE_TYPE_TIME: return JacksonValueTime.class; case JacksonValue.JSON_VALUE_TYPE_GLOBE_COORDINATES: return JacksonValueGlobeCoordinates.class; case JacksonValue.JSON_VALUE_TYPE_QUANTITY: return JacksonValueQuantity.class; case JacksonValue.JSON_VALUE_TYPE_MONOLINGUAL_TEXT: return JacksonValueMonolingualText.class; default: throw new JsonMappingException("Property values of type \"" + jsonType + "\" are not supported yet."); } }
From source file:com.github.tomakehurst.wiremock.matching.StringValuePatternJsonDeserializer.java
private EqualToJsonPattern deserializeEqualToJson(JsonNode rootNode) throws JsonMappingException { if (!rootNode.has("equalToJson")) { throw new JsonMappingException(rootNode.toString() + " is not a valid comparison"); }/* w w w. ja v a 2 s . co m*/ String operand = rootNode.findValue("equalToJson").textValue(); boolean ignoreArrayOrder = fromNullable(rootNode.findValue("ignoreArrayOrder")); boolean ignoreExtraElements = fromNullable(rootNode.findValue("ignoreExtraElements")); return new EqualToJsonPattern(operand, ignoreArrayOrder, ignoreExtraElements); }
From source file:org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285JSONMapper.java
public RFC7285NetworkMap.Filter asNetworkMapFilter(String json) throws Exception { RFC7285NetworkMap.Filter ret = mapper.readValue(json, RFC7285NetworkMap.Filter.class); if (ret.pids == null) { throw new JsonMappingException("Missing field:pids"); }/* w w w. jav a2 s . c o m*/ return ret; }
From source file:org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285JSONMapper.java
public RFC7285CostMap.Filter asCostMapFilter(String json) throws Exception { RFC7285CostMap.Filter ret = mapper.readValue(json, RFC7285CostMap.Filter.class); if (ret.costType == null) { throw new JsonMappingException("Missing field:cost-type"); }/*www . j a va 2 s . c o m*/ if (ret.pids == null) { throw new JsonMappingException("Missing field:pids"); } return ret; }
From source file:com.github.tomakehurst.wiremock.matching.StringValuePatternJsonDeserializer.java
private MatchesXPathPattern deserialiseMatchesXPathPattern(JsonNode rootNode) throws JsonMappingException { if (!rootNode.has("matchesXPath")) { throw new JsonMappingException(rootNode.toString() + " is not a valid comparison"); }/* ww w.jav a 2s .co m*/ String operand = rootNode.findValue("matchesXPath").textValue(); JsonNode namespacesNode = rootNode.findValue("xPathNamespaces"); Map<String, String> namespaces = namespacesNode != null ? toNamespaceMap(namespacesNode) : Collections.<String, String>emptyMap(); return new MatchesXPathPattern(operand, namespaces); }
From source file:org.venice.piazza.servicecontroller.taskmanaged.TaskManagedTests.java
/** * Tests updating a Status//from w ww . j a va2s .co m */ @Test public void testStatusUpdate() throws JsonProcessingException, MongoException, InvalidInputException { // Mock StatusUpdate mockUpdate = new StatusUpdate(StatusUpdate.STATUS_RUNNING); ServiceJob mockJob = new ServiceJob("job123", "service123"); Mockito.when(mongoAccessor.getServiceJob(Mockito.eq("service123"), Mockito.eq("job123"))) .thenReturn(mockJob); // Test - Kafka succeeds serviceTaskManager.processStatusUpdate("service123", "job123", mockUpdate); // Test - Final Status mockUpdate = new StatusUpdate(StatusUpdate.STATUS_SUCCESS); serviceTaskManager.processStatusUpdate("service123", "job123", mockUpdate); // Test - Kafka fails Mockito.when(objectMapper.writeValueAsString(Mockito.any())).thenThrow(new JsonMappingException("Oops")); serviceTaskManager.processStatusUpdate("service123", "job123", mockUpdate); }