Example usage for com.fasterxml.jackson.databind JavaType toCanonical

List of usage examples for com.fasterxml.jackson.databind JavaType toCanonical

Introduction

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

Prototype

public abstract String toCanonical();

Source Link

Document

Method that can be used to serialize type into form from which it can be fully deserialized from at a later point (using TypeFactory from mapper package).

Usage

From source file:org.smartdeveloperhub.vocabulary.config.ConfigurationFactory.java

static <T> T convert(final Object source, final Type type) {
    final ObjectMapper mapper = parsingMapper();
    final JavaType constructType = mapper.getTypeFactory().constructType(type);
    checkArgument(mapper.canDeserialize(constructType), "%s is not a valid configuration class",
            constructType.toCanonical());
    return mapper.convertValue(source, constructType);
}

From source file:org.camunda.spin.json.tree.JsonTreeMapJsonToJavaTest.java

@Test
public void shouldMapListByCanonicalString() throws JsonProcessingException {
    JavaType desiredType = TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, Order.class);

    List<Order> orders = JSON(EXAMPLE_JSON_COLLECTION).mapTo(desiredType.toCanonical());

    assertThat(orders.size()).isEqualTo(1);
    assertIsExampleOrder(orders.get(0));
}

From source file:cherry.foundation.testtool.stub.StubServiceImpl.java

@Override
public String thenReturn(String className, String methodName, int methodIndex, final String value,
        final String valueType) {
    return executeWithMapping(className, methodName, methodIndex, new Function<Method, Object>() {
        @Override/* w  w  w . j a v a 2 s .  c om*/
        public Object apply(Method method) {
            JavaType returnType = objectMapper.getTypeFactory().constructType(method.getGenericReturnType());
            if (StringUtils.isNotEmpty(valueType)) {
                returnType = objectMapper.getTypeFactory().constructFromCanonical(valueType);
            }
            try {
                Object v = objectMapper.readValue(value, returnType);
                repository.get(method).thenReturn(v, returnType.toCanonical());
                return Boolean.TRUE;
            } catch (IOException ex) {
                return ToMapUtil.fromThrowable(ex, Integer.MAX_VALUE);
            }
        }
    });
}

From source file:cherry.foundation.testtool.stub.StubServiceImpl.java

@Override
public String alwaysReturn(String className, String methodName, int methodIndex, final String value,
        final String valueType) {
    return executeWithMapping(className, methodName, methodIndex, new Function<Method, Object>() {
        @Override/* w  w  w.  ja va  2  s.  co m*/
        public Object apply(Method method) {
            JavaType returnType = objectMapper.getTypeFactory().constructType(method.getGenericReturnType());
            if (StringUtils.isNotEmpty(valueType)) {
                returnType = objectMapper.getTypeFactory().constructFromCanonical(valueType);
            }
            try {
                Object v = objectMapper.readValue(value, returnType);
                repository.get(method).alwaysReturn(v, returnType.toCanonical());
                return Boolean.TRUE;
            } catch (IOException ex) {
                return ToMapUtil.fromThrowable(ex, Integer.MAX_VALUE);
            }
        }
    });
}

From source file:io.swagger.inflector.processors.JacksonProcessor.java

@Override
public Object process(MediaType mediaType, InputStream entityStream, JavaType javaType) {
    try {// ww  w. j a va2s . co m
        if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) {
            return Json.mapper().readValue(entityStream, javaType);
        }
        if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType)) {
            return XML.readValue(entityStream, javaType);
        }
        if (APPLICATION_YAML_TYPE.isCompatible(mediaType)) {
            return Yaml.mapper().readValue(entityStream, javaType);
        }
    } catch (IOException e) {
        LOGGER.error(
                "unable to extract entity from content-type `" + mediaType + "` to " + javaType.toCanonical(),
                e);
    }

    return null;
}