Example usage for com.fasterxml.jackson.core ObjectCodec readValue

List of usage examples for com.fasterxml.jackson.core ObjectCodec readValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core ObjectCodec readValue.

Prototype

public abstract <T> T readValue(JsonParser jp, ResolvedType valueType)
        throws IOException, JsonProcessingException;

Source Link

Document

Method to deserialize JSON content into a POJO, type specified with fully resolved type object (so it can be a generic type, including containers like java.util.Collection and java.util.Map ).

Usage

From source file:de.dfki.asr.compass.rest.serialization.AbstractIDToEntityDeserializer.java

@Override
public EntityType deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    Long id = oc.readValue(jp, new TypeReference<Long>() {
    });/*w w w  . java2s  . co  m*/
    try {
        return referenceById(id);
    } catch (EntityNotFoundException e) {
        throw new IOException("Cannot load from Database", e);
    }
}

From source file:de.dfki.asr.compass.rest.serialization.RenderGeometryDeserializer.java

@Override
public RenderGeometry deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    Long id = oc.readValue(jp, new TypeReference<Long>() {
    });//from w  ww .  ja va  2  s.c  o  m
    try {
        return (RenderGeometry) manager.referenceById(id);
    } catch (EntityNotFoundException e) {
        throw new IOException("Cannot load from Database", e);
    }
}

From source file:de.dfki.asr.compass.rest.serialization.ReferenceDeserializer.java

@Override
public EntityClass deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    Long id = oc.readValue(jp, new TypeReference<Long>() {
    });/*  w  ww .j  a va2  s  .  c om*/
    try {
        return manager.referenceById(id);
    } catch (EntityNotFoundException e) {
        throw new IOException("Cannot load from Database", e);
    }
}

From source file:de.avpptr.umweltzone.models.CircuitDeserializer.java

@Override
public Circuit deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    Circuit circuit = new Circuit();
    ObjectCodec codec = parser.getCodec();
    GeoPoint[] coordinates = codec.readValue(parser, GeoPoint[].class);
    circuit.setCoordinates(Arrays.asList(coordinates));
    return circuit;
}

From source file:de.dfki.asr.compass.rest.serialization.AbstractIDListDeserializer.java

@Override
public List<EntityType> deserialize(final JsonParser jp, final DeserializationContext dc)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    List<Long> ids = oc.readValue(jp, new TypeReference<List<Long>>() {
    });/*from  w  ww  .  j  a va2 s  .  c  om*/
    List<EntityType> refs = new LinkedList<>();
    try {
        for (Long id : ids) {
            refs.add(referenceById(id));
        }
        return refs;
    } catch (EntityNotFoundException e) {
        throw new IOException("Cannot load from Database", e);
    }
}

From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.deserializers.OldLabelsDescriptionsDeserializer.java

@Override
public LinkedHashMap<String, String> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    LinkedHashMap<String, String> result = null;

    // Is the alias broken, i.e., it starts with '['
    if (jp.getCurrentToken().equals(JsonToken.START_ARRAY)) {
        result = new LinkedHashMap<String, String>();
        jp.nextToken();/*from  w  ww  .j  a  va2  s  . co  m*/
        if (!jp.getCurrentToken().equals(JsonToken.END_ARRAY)) {
            logger.warn("Token " + JsonToken.END_ARRAY + " expected");
        }
    } else {
        ObjectCodec mapper = jp.getCodec();
        result = mapper.readValue(jp, new TypeReference<LinkedHashMap<String, String>>() {
        });
    }

    return result;
}

From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.deserializers.OldSitelinksDeserializer.java

@Override
public LinkedHashMap<String, OldJacksonSiteLink> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    LinkedHashMap<String, OldJacksonSiteLink> result = null;

    // Is the alias broken, i.e., it starts with '['
    if (jp.getCurrentToken().equals(JsonToken.START_ARRAY)) {
        result = new LinkedHashMap<String, OldJacksonSiteLink>();
        jp.nextToken();/* www . j a  v  a 2 s  .  com*/
        if (!jp.getCurrentToken().equals(JsonToken.END_ARRAY)) {
            logger.warn("Token " + JsonToken.END_ARRAY + " expected");
        }
    } else {
        ObjectCodec mapper = jp.getCodec();
        result = mapper.readValue(jp, new TypeReference<LinkedHashMap<String, OldJacksonSiteLink>>() {
        });
    }

    return result;
}

From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.deserializers.OldAliasesDeserializer.java

@Override
public LinkedHashMap<String, List<String>> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    LinkedHashMap<String, List<String>> result = new LinkedHashMap<String, List<String>>();

    // Is the alias broken, i.e., it starts with '['
    if (jp.getCurrentToken().equals(JsonToken.START_ARRAY)) {
        jp.nextToken();/*from   www  .  ja  v a 2s  .com*/
        if (!jp.getCurrentToken().equals(JsonToken.END_ARRAY)) {
            logger.warn("Token " + JsonToken.END_ARRAY + " expected");
        }
    } else {
        ObjectCodec mapper = jp.getCodec();
        result = mapper.readValue(jp, new TypeReference<LinkedHashMap<String, OldAliasList>>() {
        });
    }

    return result;
}

From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.OldAliasListDeserializer.java

@Override
public List<String> deserialize(JsonParser p, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    List<String> result;

    ObjectCodec codec = p.getCodec();

    if (p.getCurrentToken().equals(JsonToken.START_ARRAY)) {
        result = codec.readValue(p, new TypeReference<List<String>>() {
        });/*from  w ww .j a v a 2s.  co m*/
    } else {
        LinkedHashMap<Integer, String> map = codec.readValue(p,
                new TypeReference<LinkedHashMap<Integer, String>>() {
                });

        result = new ArrayList<String>(map.values());
    }
    return result;
}

From source file:de.undercouch.bson4jackson.BsonParser.java

/**
 * Fully reads an embedded document, reusing this parser
 * @return the parsed document//from ww w.  j a  v a2 s  .  c o  m
 * @throws IOException if the document could not be read
 */
protected Map<String, Object> readDocument() throws IOException {
    ObjectCodec codec = getCodec();
    if (codec == null) {
        throw new IllegalStateException(
                "Could not parse embedded document " + "because BSON parser has no codec");
    }
    _currToken = handleNewDocument(false);
    return codec.readValue(this, new TypeReference<Map<String, Object>>() {
    });
}