Example usage for com.fasterxml.jackson.databind ObjectMapper reader

List of usage examples for com.fasterxml.jackson.databind ObjectMapper reader

Introduction

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

Prototype

public ObjectReader reader(ContextAttributes attrs) 

Source Link

Document

Factory method for constructing ObjectReader that will use specified default attributes.

Usage

From source file:org.springframework.social.twitter.api.impl.StreamEventMixin.java

private static TwitterProfile toProfile(final JsonNode node) throws IOException {
    if (null == node || node.isNull() || node.isMissingNode()) {
        return null;
    }/*  w ww .  ja v  a 2 s .  co  m*/
    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new TwitterModule());
    return mapper.reader(TwitterProfile.class).readValue(node);
}

From source file:org.jongo.marshall.jackson.configuration.DefaultReaderCallback.java

public ObjectReader getReader(ObjectMapper mapper, Class<?> clazz) {
    return mapper.reader(clazz);
}

From source file:org.jongo.marshall.jackson.configuration.ViewReaderCallback.java

public ObjectReader getReader(ObjectMapper mapper, Class<?> clazz) {
    return mapper.reader(clazz).withView(viewClass);
}

From source file:org.springframework.social.linkedin.api.impl.json.CodeDeserializer.java

@Override
public String deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    if (jp.hasCurrentToken() && jp.getCurrentToken().equals(JsonToken.START_OBJECT)) {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode node = mapper.reader(JsonNode.class).readValue(jp);
        return node.has(VALUE) ? node.get(VALUE).textValue() : null;
    }/*from   w  w  w. j  a  v  a  2  s.c om*/

    throw ctxt.mappingException("Expected JSON object");
}

From source file:com.auth0.api.internal.ApplicationInfoRequest.java

public ApplicationInfoRequest(Handler handler, OkHttpClient client, HttpUrl url, ObjectMapper mapper) {
    super(handler, url, client, mapper.reader(Application.class), null);
}

From source file:br.unicamp.cst.trafficUnjammer.experiments.communication.JsonHandler.java

/**
 * Convert a String to a Object from a specific class
 * @param <T>/*from  w  ww  .java 2  s. com*/
 * @param objectClass
 * @param jsonData
 * @return
 */
public <T> Object fromJsonDataToObject(Class<T> objectClass, String jsonData) {

    ObjectMapper mapper = new ObjectMapper();
    ObjectReader reader = mapper.reader(objectClass);
    T parsed = null;
    try {
        parsed = reader.readValue(jsonData);
    } catch (JsonProcessingException e) {

    } catch (IOException e) {

    }

    return parsed;
}

From source file:com.auth0.api.internal.SimpleRequest.java

public SimpleRequest(Handler handler, HttpUrl url, OkHttpClient client, ObjectMapper mapper,
        String httpMethod) {//from w w  w .  j  a v a2 s .  com
    super(handler, url, client, mapper.reader(new TypeReference<Map<String, Object>>() {
    }), mapper.writer());
    this.errorReader = mapper.reader(new TypeReference<Map<String, Object>>() {
    });
    this.method = httpMethod;
}

From source file:com.auth0.api.internal.SimpleRequest.java

public SimpleRequest(Handler handler, HttpUrl url, OkHttpClient client, ObjectMapper mapper, String httpMethod,
        Class<T> clazz) {/*  w  w  w.j  a  va 2  s.  c  o  m*/
    super(handler, url, client, mapper.reader(clazz), mapper.writer());
    this.errorReader = mapper.reader(new TypeReference<Map<String, Object>>() {
    });
    this.method = httpMethod;
}

From source file:ro.fortsoft.dataset.json.JsonDataSet.java

protected void init() {
    ObjectMapper mapper = new ObjectMapper();
    ObjectReader reader = mapper.reader(Map.class);

    try {/*  w  w w  .j  a va2s.  com*/
        rows = reader.readValues(inputStream);
    } catch (IOException e) {
        throw new DataSetException(e);
    }
}

From source file:org.wikidata.wdtk.datamodel.json.jackson.JsonSerializerTest.java

@Test
public void testSerializer() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonSerializer serializer = new JsonSerializer(out);

    ItemDocument id1 = Datamodel.makeItemDocument(DataObjectFactoryImplTest.getTestItemIdValue(1),
            Collections//from w  ww.j  av  a 2 s  .c o  m
                    .<MonolingualTextValue>singletonList(Datamodel.makeMonolingualTextValue("Label1", "lang1")),
            Collections.<MonolingualTextValue>emptyList(), Collections.<MonolingualTextValue>emptyList(),
            DataObjectFactoryImplTest.getTestStatementGroups(1, 24, 1, EntityIdValue.ET_ITEM),
            Collections.<String, SiteLink>emptyMap());
    ItemDocument id2 = Datamodel.makeItemDocument(DataObjectFactoryImplTest.getTestItemIdValue(2),
            Collections.<MonolingualTextValue>emptyList(), Collections.<MonolingualTextValue>emptyList(),
            Collections.<MonolingualTextValue>emptyList(),
            DataObjectFactoryImplTest.getTestStatementGroups(2, 23, 1, EntityIdValue.ET_ITEM),
            Collections.<String, SiteLink>singletonMap("enwiki",
                    Datamodel.makeSiteLink("Title2", "enwiki", Collections.<String>emptyList())));
    PropertyDocument pd1 = Datamodel.makePropertyDocument(DataObjectFactoryImplTest.getTestPropertyIdValue(1),
            Collections.<MonolingualTextValue>emptyList(), Collections.<MonolingualTextValue>emptyList(),
            Collections
                    .<MonolingualTextValue>singletonList(Datamodel.makeMonolingualTextValue("Alias1", "lang1")),
            Collections.<StatementGroup>emptyList(),
            Datamodel.makeDatatypeIdValue(DatatypeIdValue.DT_COMMONS_MEDIA));

    serializer.open();
    serializer.processItemDocument(id1);
    serializer.processItemDocument(id2);
    serializer.processPropertyDocument(pd1);
    serializer.close();

    ArrayList<EntityDocument> inputDocuments = new ArrayList<>();
    inputDocuments.add(id1);
    inputDocuments.add(id2);
    inputDocuments.add(pd1);

    ArrayList<EntityDocument> outputDocuments = new ArrayList<>();

    ObjectMapper mapper = new ObjectMapper();
    ObjectReader documentReader = mapper.reader(JacksonTermedStatementDocument.class);

    MappingIterator<JacksonTermedStatementDocument> documentIterator = documentReader
            .readValues(out.toString());
    while (documentIterator.hasNextValue()) {
        JacksonTermedStatementDocument document = documentIterator.nextValue();
        document.setSiteIri("foo:");
        outputDocuments.add(document);
    }
    documentIterator.close();

    for (int i = 0; i < outputDocuments.size(); i++) {
        assertEquals(inputDocuments.get(i), outputDocuments.get(i));
    }
    assertEquals(serializer.getEntityDocumentCount(), 3);
}