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:uk.co.sdev.async.http.ning.Parallel2SequentialCompletableFutureClientTest.java

@Override
protected CompletableFuture<Optional<Quotient>> divide(Numerator numerator, Denominator denominator)
        throws IOException {
    String url = "http://localhost:9101/divide/" + numerator.getValue().toString() + "/"
            + denominator.getValue().toString();
    return completableFutureClient.get(url, new TypeReference<Optional<Quotient>>() {
    }).handle(withFallback(Optional.<Quotient>empty()));
}

From source file:com.facebook.presto.accumulo.iterators.AbstractBooleanFilter.java

@Override
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options,
        IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    for (Entry<String, String> e : options.entrySet()) {
        try {/*from w w  w .j a v  a2 s.c o m*/
            Map<String, String> props = OBJECT_MAPPER.readValue(e.getValue(),
                    new TypeReference<Map<String, String>>() {
                    });
            String clazz = props.remove(FILTER_JAVA_CLASS_NAME);
            RowFilter f = (RowFilter) Class.forName(clazz).newInstance();
            f.init(this, props, env);
            filters.add(f);
            LOG.info("%s: Added Filter %s", super.toString(), f);
        } catch (Exception ex) {
            throw new IllegalArgumentException(
                    "Failed to deserialize Filter information from JSON value " + e.getValue(), ex);
        }
    }
}

From source file:com.cloudant.mazha.OpenRevisionTest.java

@Test
public void deserialization_missingRevision() throws IOException {
    String s = FileUtils.readFileToString(new File("fixture/open_revisions_missing.json"));
    List<OpenRevision> openRevisionList = jsonHelper.fromJson(new StringReader(s),
            new TypeReference<List<OpenRevision>>() {
            });/*from w w w. j  a v a 2  s. c o  m*/
    Assert.assertThat(openRevisionList, hasSize(1));
    Assert.assertTrue(openRevisionList.get(0) instanceof MissingOpenRevision);
    MissingOpenRevision missingOpenRevision = (MissingOpenRevision) openRevisionList.get(0);
    Assert.assertEquals("2-x", missingOpenRevision.getRevision());
}

From source file:org.ontologyengineering.conceptdiagrams.web.server.serialization.JacksonClassSerializer.java

public ArrayList<Command> readSerializedCommandHistory(String file) {
    ArrayList<Command> result = null;

    File outfile = new File(file);
    try {//  w w w  .j  a  v a2  s  . c o m
        result = mapper.readValue(outfile, new TypeReference<ArrayList<Command>>() {
        });
    } catch (IOException e) {
        logger.info("Exception reading serialized", e);
    }

    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();//from  w w w . ja v  a2 s . com

    if (p.getCurrentToken().equals(JsonToken.START_ARRAY)) {
        result = codec.readValue(p, new TypeReference<List<String>>() {
        });
    } else {
        LinkedHashMap<Integer, String> map = codec.readValue(p,
                new TypeReference<LinkedHashMap<Integer, String>>() {
                });

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

From source file:io.gravitee.definition.jackson.datatype.services.core.deser.ServiceDeserializer.java

@Override
public Service deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);
    String serviceName = node.fieldNames().next();

    Class<? extends Service> serviceClass = registeredServices.get(serviceName);
    if (serviceClass == null) {
        return null;
    }/*from   ww w  .ja  va 2s .co  m*/

    return node.elements().next().traverse(jp.getCodec()).readValueAs(new TypeReference<Service>() {
        @Override
        public Type getType() {
            return serviceClass;
        }
    });
}

From source file:com.netflix.edda.EddaRoute53Client.java

public ListResourceRecordSetsResult listResourceRecordSets(ListResourceRecordSetsRequest request) {
    validateNotEmpty("HostedZoneId", request.getHostedZoneId());

    TypeReference<List<ResourceRecordSet>> ref = new TypeReference<List<ResourceRecordSet>>() {
    };/*from w  w w .  j a v a  2  s  .com*/
    String hostedZoneId = request.getHostedZoneId();

    String url = config.url() + "/api/v2/aws/hostedRecords;_expand;zone.id=" + hostedZoneId;
    try {
        List<ResourceRecordSet> resourceRecordSets = parse(ref, doGet(url));
        return new ListResourceRecordSetsResult().withResourceRecordSets(resourceRecordSets);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

From source file:com.ibm.ws.lars.rest.model.RepositoryObject.java

protected static Map<String, Object> readJsonState(String json) throws InvalidJsonAssetException {
    try {//from  www.  j  a va  2  s  . c  o  m
        return reader.readValue(json, new TypeReference<Map<String, Object>>() {
        });
    } catch (JsonParseException e) {
        throw new InvalidJsonAssetException(e);
    } catch (JsonMappingException e) {
        throw new InvalidJsonAssetException(e);
    } catch (IOException e) {
        // No idea what would cause this.
        throw new InvalidJsonAssetException(e);
    }
}

From source file:com.xeiam.xchange.mtgox.v2.service.marketdata.polling.streaming.DepthUpdateJSONTest.java

@Test
public void testStreamingUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = DepthUpdateJSONTest.class
            .getResourceAsStream("/v2/marketdata/streaming/example-depth-streaming-data.json");

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    Map<String, Object> userInMap = mapper.readValue(is, new TypeReference<Map<String, Object>>() {
    });/*from  ww w  .  ja va2s.  com*/

    MtGoxDepthUpdate mtGoxDepthUpdate = mapper.readValue(mapper.writeValueAsString(userInMap.get("depth")),
            MtGoxDepthUpdate.class);

    // Verify that the example data was unmarshalled correctly
    assertThat(mtGoxDepthUpdate.getPriceInt()).isEqualTo(6250000L);
    assertThat(mtGoxDepthUpdate.getCurrency()).isEqualTo("USD");

}

From source file:fi.helsinki.opintoni.integration.coursepage.CoursePageMockClient.java

@Override
public CoursePageCourseImplementation getCoursePage(String courseImplementationId) {
    Resource courses = (courseImplementationId != null) ? courses1 : courses2;
    return getResponse(courses, new TypeReference<CoursePageCourseImplementation>() {
    });/*from   ww  w  .jav a2s .co m*/
}