Example usage for com.fasterxml.jackson.core JsonParser readValueAs

List of usage examples for com.fasterxml.jackson.core JsonParser readValueAs

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonParser readValueAs.

Prototype

@SuppressWarnings("unchecked")
public <T> T readValueAs(TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException 

Source Link

Document

Method to deserialize JSON content into a Java type, reference to which is passed as argument.

Usage

From source file:com.amazonaws.services.dynamodb.datamodeling.JsonMarshaller.java

@Override
public T unmarshall(Class<T> clazz, String obj) {
    try {//  w  w w .  ja  v  a 2  s.co m
        JsonFactory jsonFactory = new MappingJsonFactory();
        JsonParser jsonParser = jsonFactory.createJsonParser(new StringReader(obj));
        return jsonParser.readValueAs(clazz);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.muk.ext.core.jackson.PairDeserializer.java

@Override
public Pair<String, Object> deserialize(JsonParser p, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    final Object[] array = p.readValueAs(Object[].class);
    return Pair.of((String) array[0], array[1]);
}

From source file:org.springframework.social.facebook.api.impl.json.PictureDeserializer.java

@Override
public String deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonNode node = jp.readValueAs(JsonNode.class);
    if (node.isObject() && node.has("data")) {
        return node.get("data").get("url").asText();
    } else if (node.isTextual()) {
        return node.asText();
    }//from www  .  java2  s  .  c  om
    return null;
}

From source file:org.hawkular.apm.tests.dockerized.TestScenariosFinder.java

public <T> T deserialize(String json, Class<T> type) throws IOException {
    JsonParser parser = objectMapper.getFactory().createParser(json);
    return parser.readValueAs(type);
}

From source file:com.zenesis.qx.remote.ProxiedDeserializer.java

@Override
public Proxied deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    Object obj = jp.readValueAs(Object.class);
    if (obj == null)
        return null;
    return RequestHandler.getCurrentHandler().getProxied(Integer.parseInt(obj.toString()));
}

From source file:org.hawkular.datamining.api.SerializationTest.java

private <T> T deserialize(String json, Class<T> type) throws Exception {
    JsonParser parser = mapper.getFactory().createParser(json);

    return parser.readValueAs(type);
}

From source file:org.zalando.jackson.datatype.money.MonetaryAmountDeserializer.java

@Override
public MonetaryAmount deserialize(final JsonParser parser, final DeserializationContext context)
        throws IOException {
    final MoneyNode node = parser.readValueAs(MoneyNode.class);
    return factory.create(node.getAmount(), node.getCurrency());
}

From source file:reactor.js.core.json.JSObjectDeserializer.java

@SuppressWarnings("unchecked")
@Override/*from   w ww.  jav  a 2  s .  co m*/
public JSObject deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    Object obj = jp.readValueAs(Object.class);

    Object parent = ctxt.getAttribute("parent");
    ctxt.setAttribute("parent", obj);

    if (Map.class.isInstance(obj)) {
        return new JavaScriptObject((Map) obj, null, null, parent);
    } else if (List.class.isInstance(obj)) {
        return new JavaScriptArray((List) obj);
    } else {
        throw new JsonMappingException("Cannot convert value to a valid JSON object", jp.getCurrentLocation());
    }
}

From source file:com.arpnetworking.jackson.EnumerationDeserializer.java

/**
 * {@inheritDoc}/*w ww . j a va 2  s  .c o  m*/
 */
@Override
public T deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
    final String stringValue = jp.readValueAs(String.class);
    try {
        return _strategy.toEnum(_enumClass, stringValue);
    } catch (final EnumerationNotFoundException e) {
        throw new IllegalArgumentException(
                String.format("cannot deserialize this enumeration, strategy=%s", _strategy), e);
    }
}

From source file:com.streamsets.datacollector.record.FieldDeserializer.java

@Override
@SuppressWarnings("unchecked")
public FieldJson deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    Field field = parse(jp.readValueAs(Map.class));
    return new FieldJson(field);
}