Example usage for com.fasterxml.jackson.databind JsonMappingException JsonMappingException

List of usage examples for com.fasterxml.jackson.databind JsonMappingException JsonMappingException

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonMappingException JsonMappingException.

Prototype

public JsonMappingException(String paramString) 

Source Link

Usage

From source file:com.evrythng.java.wrapper.mapping.PropertyDeserializer.java

@Override
public Property<?> deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException {

    ObjectMapper mapper = JSONUtils.OBJECT_MAPPER;
    JsonNode node = mapper.readTree(jp);
    JsonNode valueNode = node.get(Property.FIELD_VALUE);
    if (valueNode == null) {
        throw new JsonMappingException("Cannot deserialize property without value field");
    }//from  w  ww .  ja  v  a  2  s .  c o  m
    Object value = getFieldValue(valueNode);
    Property.Type type = Property.Type.forPropertyValue(value);
    Class<? extends Property<?>> propertyClass = propertyClassForType(type);
    return mapper.readValue(node.toString(), propertyClass);
}

From source file:org.mongojack.internal.MongoJackDeserializers.java

@Override
public JsonDeserializer<?> findBeanDeserializer(JavaType type, DeserializationConfig config,
        BeanDescription beanDesc) throws JsonMappingException {
    if (type.getRawClass() == DBRef.class) {
        if (type.containedTypeCount() != 2) {
            throw new JsonMappingException("Property doesn't declare object and key type");
        }//from  ww w .j  a v  a2s  .c  o m
        JavaType objectType = type.containedType(0);
        JavaType keyType = type.containedType(1);
        return new DBRefDeserializer(objectType, keyType);
    }
    return super.findBeanDeserializer(type, config, beanDesc);
}

From source file:org.eyeseetea.malariacare.layout.dashboard.deserializers.DatabaseOriginTypeDeserializer.java

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    DatabaseOriginType databaseOriginType = DatabaseOriginType.fromId(p.getValueAsString());
    if (databaseOriginType != null) {
        return databaseOriginType;
    }//  w w w .j a v a 2s. c o m
    throw new JsonMappingException("'originType' must be 'dhis' or 'csv'");
}

From source file:org.eyeseetea.malariacare.layout.dashboard.deserializers.DashboardListFilterDeserializer.java

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    DashboardListFilter dashboardListFilter = DashboardListFilter.fromId(p.getValueAsString());
    if (dashboardListFilter != null) {
        return dashboardListFilter;
    }/*from   w ww.  j  av a  2  s  .  c  o m*/
    throw new JsonMappingException("'listFilter' must be 'lastForOU' or 'none'");
}

From source file:com.servioticy.datamodel.sensorupdate.SUChannel.java

@JsonSetter("current-value")
public void setNotNullCurrentValue(Object currentValue) throws JsonMappingException {
    if (currentValue == null) {
        throw new JsonMappingException("'current-value' must be different from 'null'");
    }//w w w  .ja v  a  2  s  .c  o m
    setCurrentValue(currentValue);
}

From source file:com.evrythng.java.wrapper.mapping.BatchPopulatingTaskInputParametersDeserializer.java

@Override
public BatchPopulatingTask.InputParameters deserialize(final JsonParser jp, final DeserializationContext ctx)
        throws IOException {

    ObjectMapper mapper = JSONUtils.OBJECT_MAPPER;
    JsonNode node = mapper.readTree(jp);
    JsonNode typeNode = node.get(BatchPopulatingTask.InputParameters.FIELD_TYPE);
    if (typeNode == null) {
        throw new JsonMappingException("Cannot deserialize adi generation input parameters without type field");
    }/* w w  w  . j  a v a2  s  .c  om*/
    String typeRaw = getFieldValue(typeNode);
    Class<? extends BatchPopulatingTask.InputParameters> subtypeClass = classForType(
            BatchPopulatingTask.InputParameters.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.CostRequest asCostRequest(String json) throws Exception {
    RFC7285Endpoint.CostRequest ret = mapper.readValue(json, RFC7285Endpoint.CostRequest.class);
    if (ret.costType == null) {
        throw new JsonMappingException("Missing field:cost-type");
    }//w  ww  .ja v  a2s .co  m
    if (ret.endpoints == null) {
        throw new JsonMappingException("Missing field:endpoints");
    }
    return ret;
}

From source file:com.servioticy.datamodel.serviceobject.SOStream.java

@JsonSetter("channels")
public void setNotNullOrEmptyChannels(LinkedHashMap<String, SOChannel> channels) throws JsonMappingException {
    if (channels == null || channels.size() < 1) {
        throw new JsonMappingException("At least one channel is required");
    }/* w  ww.j a va  2s .c  o m*/
    setChannels(channels);
}

From source file:com.expedia.seiso.web.controller.ExceptionHandlerAdviceTests.java

private void setUpTestData() {
    this.resourceNotFoundException = new ResourceNotFoundException("my-rnfe-message");
    this.jsonMappingException = new JsonMappingException("my-jme-message");
    this.runtimeException = new RuntimeException("my-re-message");
}

From source file:com.animedetour.api.sched.deserialization.PanelDateDeserializerTest.java

@Test(expected = JsonMappingException.class)
public void deserializationFailure() throws IOException {
    PanelDateDeserializer deserializer = new PanelDateDeserializer();
    JsonParser parser = Mockito.mock(JsonParser.class);
    Mockito.when(parser.getCurrentToken()).thenReturn(JsonToken.VALUE_FALSE);
    DeserializationContext context = Mockito.mock(DeserializationContext.class);
    Mockito.when(context.mappingException(Mockito.anyString()))
            .thenReturn(new JsonMappingException("Mapping failure"));

    deserializer.deserialize(parser, context);
}