List of usage examples for com.fasterxml.jackson.databind JsonMappingException JsonMappingException
public JsonMappingException(String paramString)
From source file:com.evrythng.java.wrapper.mapping.ActionJobDeserializer.java
@Override public ActionJob deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode typeNode = node.get(ActionJob.FIELD_TYPE); if (typeNode == null) { throw new JsonMappingException("Cannot deserialize actions job without type field"); }//from w ww . j av a 2 s . c o m String typeRaw = getFieldValue(typeNode); Class<? extends ActionJob> subtypeClass = classForType(ActionJob.Type.valueOf(typeRaw.toUpperCase())); return mapper.readValue(node.toString(), subtypeClass); }
From source file:com.evrythng.java.wrapper.mapping.TaskResultDeserializer.java
@Override public TaskOnBatch.BaseTaskResult deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode typeNode = node.get(TaskOnBatch.FIELD_TYPE); if (typeNode == null) { throw new JsonMappingException("Cannot deserialize task result without type field"); }/* w w w . j a v a 2 s .c o m*/ String typeRaw = getFieldValue(typeNode); Class<? extends TaskOnBatch.BaseTaskResult> subtypeClass = classForType( TaskOnBatch.BaseTaskResult.Type.valueOf(typeRaw.toUpperCase())); return mapper.readValue(node.toString(), subtypeClass); }
From source file:com.evrythng.java.wrapper.mapping.TaskOnBatchDeserializer.java
@Override public TaskOnBatch deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode typeNode = node.get(TaskOnBatch.FIELD_TYPE); if (typeNode == null) { throw new JsonMappingException("Cannot deserialize task on batch without type field"); }//from www . j av a 2 s .c om String typeRaw = getFieldValue(typeNode); Class<? extends TaskOnBatch> subtypeClass = classForType(TaskOnBatch.Type.valueOf(typeRaw.toUpperCase())); return mapper.readValue(node.toString(), subtypeClass); }
From source file:org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285JSONMapper.java
public RFC7285Endpoint.PropertyRequest asPropertyRequest(String json) throws Exception { RFC7285Endpoint.PropertyRequest ret = mapper.readValue(json, RFC7285Endpoint.PropertyRequest.class); if (ret.properties == null) { throw new JsonMappingException("Missing field:properties"); }/*w ww . ja v a 2 s . c o m*/ if (ret.endpoints == null) { throw new JsonMappingException("Missing field:endpoints"); } return ret; }
From source file:com.evrythng.java.wrapper.mapping.TaskNotificationWayDeserializer.java
@Override public Task.Notification.Way deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode typeNode = node.get(TaskOnBatch.FIELD_TYPE); if (typeNode == null) { throw new JsonMappingException("Cannot deserialize task notification way without type field"); }/* ww w. j a v a2 s .c om*/ String typeRaw = getFieldValue(typeNode); Class<? extends Task.Notification.Way> subtypeClass = classForType( Task.Notification.Way.Type.valueOf(typeRaw.toUpperCase())); return mapper.readValue(node.toString(), subtypeClass); }
From source file:org.ohdsi.webapi.feasibility.TheraputicAreaDeserializer.java
@Override public TheraputicArea deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException { TheraputicArea type = TheraputicArea.fromId(jp.getValueAsInt()); if (type != null) { return type; }/*from w w w .j a v a2 s. c o m*/ throw new JsonMappingException("invalid value for type, must be 'one' or 'two'"); }
From source file:com.evrythng.java.wrapper.mapping.ShortIdTemplateDeserializer.java
@Override public ShortIdTemplate deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode typeNode = node.get(ShortIdTemplate.FIELD_TYPE); if (typeNode == null) { throw new JsonMappingException("Cannot deserialize task on batch without type field"); }//from w w w . j av a 2s . co m String typeRaw = getFieldValue(typeNode); Class<? extends ShortIdTemplate> subtypeClass = classForType( ShortIdTemplate.Type.valueOf(typeRaw.toUpperCase())); return mapper.readValue(node.toString(), subtypeClass); }
From source file:com.hpcloud.mon.app.validation.Validation.java
/** * @throws JsonMappingException if the {@code value} is not valid for the {@code type} *//*from w ww. j a va 2 s . c o m*/ public static <T extends Enum<T>> T parseAndValidate(Class<T> type, String value) throws JsonMappingException { for (T constant : type.getEnumConstants()) if (constant.name().equalsIgnoreCase(value)) return constant; List<String> acceptedValues = new ArrayList<>(); for (T constant : type.getEnumConstants()) acceptedValues.add(constant.name()); throw new JsonMappingException(String.format("%s was not one of %s", value, acceptedValues)); }
From source file:com.evrythng.java.wrapper.mapping.BatchPopulatingTaskOutputParametersDeserializer.java
@Override public BatchPopulatingTask.OutputParameters deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); JsonNode typeNode = node.get(BatchPopulatingTask.OutputParameters.FIELD_TYPE); if (typeNode == null) { throw new JsonMappingException( "Cannot deserialize adi generation output parameters without type field"); }//from w ww . j a v a 2s .co m String typeRaw = getFieldValue(typeNode); Class<? extends BatchPopulatingTask.OutputParameters> subtypeClass = classForType( BatchPopulatingTask.OutputParameters.Type.valueOf(typeRaw.toUpperCase())); return mapper.readValue(node.toString(), subtypeClass); }
From source file:org.eyeseetea.malariacare.layout.dashboard.deserializers.DashboardOrientationDeserializer.java
@Override public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { DashboardOrientation dashboardOrientation = DashboardOrientation.fromId(p.getValueAsString()); if (dashboardOrientation != null) { return dashboardOrientation; }/* w w w .java2 s . c o m*/ throw new JsonMappingException("'orientation' must be 'horizontal' or 'vertical'"); }