Example usage for com.fasterxml.jackson.core.type TypeReference TypeReference

List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.type TypeReference TypeReference.

Prototype

protected TypeReference() 

Source Link

Usage

From source file:com.globo.globodns.client.api.RecordAPI.java

@Override
protected Type getListType() {
    return new TypeReference<List<Record>>() {
    }.getType();
}

From source file:com.evrythng.java.wrapper.service.RedirectorService.java

/**
 * Load a single Account level {@link RedirectorRules}.
 * <p>/*from   w  w  w  . ja v a  2  s .  c o m*/
 * GET {@value #PATH_ACCOUNT_REDIRECTOR}
 *
 * @return a preconfigured {@link Builder}.
 */
public Builder<RedirectorRules> redirectorRulesReader() throws EvrythngClientException {

    return get(PATH_ACCOUNT_REDIRECTOR, new TypeReference<RedirectorRules>() {

    });
}

From source file:com.networknt.light.rule.post.GetPostTreeRule.java

public boolean execute(Object... objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");

    long total = DbService.getCount("Post", data);
    if (total > 0) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("total", total);
        String posts = DbService.getData("Post", data);
        List<Map<String, Object>> jsonList = mapper.readValue(posts,
                new TypeReference<List<HashMap<String, Object>>>() {
                });//from   w  w w .j a v a  2s  .  c  o  m
        result.put("posts", jsonList);
        inputMap.put("result", mapper.writeValueAsString(result));
        return true;
    } else {
        inputMap.put("result", "No post can be found.");
        inputMap.put("responseCode", 404);
        return false;
    }
}

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();//from  w  w w  .ja  v a2 s .  c  o  m
    List<Long> ids = oc.readValue(jp, new TypeReference<List<Long>>() {
    });
    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:spring.travel.site.services.LoginService.java

public CompletableFuture<Optional<User>> login(LoginData loginData) {
    try {//from w w w.  j ava  2  s.com
        String body = objectMapper.writeValueAsString(loginData);
        return client.post(loginServiceUrl, body, new TypeReference<Optional<User>>() {
        }).handle(withFallback(Optional.<User>empty()));
    } catch (Exception e) {
        return none();
    }
}

From source file:com.networknt.light.rule.comment.GetCommentRule.java

public boolean execute(Object... objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    Map<String, Object> criteria = new HashMap<String, Object>();
    criteria.put("@class", "Comment");
    long total = getTotal(data, criteria);
    if (total > 0) {
        String json = getComment(data, criteria);
        List<Map<String, Object>> comments = mapper.readValue(json,
                new TypeReference<List<HashMap<String, Object>>>() {
                });// w  w w . jav a2s  . com
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("total", total);
        result.put("comments", comments);
        inputMap.put("result", mapper.writeValueAsString(result));
        return true;
    } else {
        inputMap.put("result", "No user can be found.");
        inputMap.put("responseCode", 404);
        return false;
    }
}

From source file:com.wavemaker.commons.json.deserializer.HttpHeadersDeSerializer.java

@Override
public HttpHeaders deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    ObjectCodec codec = jp.getCodec();/*  w ww  .java2s  . c om*/
    ObjectNode root = codec.readTree(jp);
    Map<String, Object> map = ((ObjectMapper) codec).readValue(root.toString(),
            new TypeReference<LinkedHashMap<String, Object>>() {
            });
    HttpHeaders httpHeaders = new HttpHeaders();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        Object value = entry.getValue();
        if (value instanceof String) {
            httpHeaders.add(entry.getKey(), (String) entry.getValue());
        } else if (value instanceof List) {
            httpHeaders.put(entry.getKey(), (List<String>) value);
        }
    }
    return httpHeaders;
}

From source file:com.globo.globodns.client.api.AuthAPI.java

@Override
protected Type getListType() {
    return new TypeReference<List<Authentication>>() {
    }.getType();
}

From source file:com.nesscomputing.sequencer.SequencerJsonSerializationTest.java

@Test
public void testHashSequencerSerialize1() throws Exception {
    HashSequencer<String> origSeq = HashSequencer.create();

    origSeq.sequenceOrAdd("a");
    origSeq.sequenceOrAdd("b");
    origSeq.sequenceOrAdd("c");

    byte[] seq = mapper.writeValueAsBytes(origSeq);
    Sequencer<String> newSeq = mapper.readValue(seq, new TypeReference<Sequencer<String>>() {
    });/* ww w  .j a  v a2  s.  c  om*/
    assertEquals(origSeq, newSeq);
}

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();//from   w  w  w .  jav  a 2 s.co m
    Long id = oc.readValue(jp, new TypeReference<Long>() {
    });
    try {
        return manager.referenceById(id);
    } catch (EntityNotFoundException e) {
        throw new IOException("Cannot load from Database", e);
    }
}