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

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

Introduction

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

Prototype

public Type getType() 

Source Link

Usage

From source file:com.basho.riak.client.api.commands.itest.ITestORM.java

@Test
public void updateAndResolveParameterizedTypeCustom() throws ExecutionException, InterruptedException {
    // We're back to allow_mult=false as default
    Namespace ns = new Namespace(Namespace.DEFAULT_BUCKET_TYPE, bucketName.toString());
    StoreBucketPropsOperation op = new StoreBucketPropsOperation.Builder(ns).withAllowMulti(true).build();
    cluster.execute(op);//  w  w  w. j  a v a  2  s  .com
    op.get();

    RiakClient client = new RiakClient(cluster);
    Location loc = new Location(ns, "test_ORM_key5");

    TypeReference<GenericPojo<Integer>> tr = new TypeReference<GenericPojo<Integer>>() {
    };

    ConflictResolverFactory.getInstance().registerConflictResolver(tr, new MyResolver());
    ConverterFactory.getInstance().registerConverterForClass(tr, new MyConverter(tr.getType()));

    MyUpdate update = new MyUpdate();

    UpdateValue uv = new UpdateValue.Builder(loc).withUpdate(update, tr).build();

    client.execute(uv);

    // Create a sibling 
    GenericPojo<Integer> gpi = update.apply(null);
    StoreValue sv = new StoreValue.Builder(gpi, tr).withLocation(loc).build();

    client.execute(sv);

    uv = new UpdateValue.Builder(loc).withUpdate(update, tr).withStoreOption(Option.RETURN_BODY, true).build();

    UpdateValue.Response uvResp = client.execute(uv);

    gpi = uvResp.getValue(tr);
    assertNotNull(gpi);
    assertNotNull(gpi.value);
    assertEquals(3, gpi.value.intValue());

    // Check to see that the custom conversion is right
    RiakObject ro = uvResp.getValue(RiakObject.class);
    assertEquals("3", ro.getValue().toString());
}

From source file:io.coala.config.AbstractPropertyGetter.java

/**
 * @param valueTypeRef//from w  w w. ja  va  2s  .  c om
 * @return
 * @throws CoalaException if value was not configured nor any default was
 *             set
 */
@SuppressWarnings("rawtypes")
public <T> T getJSON(final TypeReference valueTypeRef) throws CoalaRuntimeException

{
    if (valueTypeRef == null)
        throw CoalaExceptionFactory.VALUE_NOT_SET.createRuntime("valueTypeRef");

    final String value = get();
    try {
        return JsonUtil.getJOM().readValue(value, valueTypeRef);
    } catch (final Throwable e) {
        throw CoalaExceptionFactory.UNMARSHAL_FAILED.createRuntime(e, value, valueTypeRef.getType());
    }
}

From source file:org.commonjava.aprox.client.core.AproxClientHttp.java

public <T> T get(final String path, final TypeReference<T> typeRef) throws AproxClientException {
    connect();//from   w  ww  . j a v  a  2  s .  co  m

    HttpGet request = null;
    CloseableHttpResponse response = null;
    CloseableHttpClient client = null;
    try {
        client = newClient();
        request = newJsonGet(buildUrl(baseUrl, path));
        response = client.execute(request);
        final StatusLine sl = response.getStatusLine();
        if (sl.getStatusCode() != 200) {
            if (sl.getStatusCode() == 404) {
                return null;
            }

            throw new AproxClientException("Error retrieving %s from: %s. Status was: %d %s (%s)",
                    typeRef.getType(), path, sl.getStatusCode(), sl.getReasonPhrase(), sl.getProtocolVersion());
        }

        final String json = entityToString(response);
        final T value = objectMapper.readValue(json, typeRef);

        return value;
    } catch (final IOException e) {
        throw new AproxClientException("AProx request failed: %s", e, e.getMessage());
    } finally {
        cleanupResources(request, response, client);
    }
}

From source file:org.commonjava.aprox.client.core.AproxClientHttp.java

public <T> T postWithResponse(final String path, final Object value, final TypeReference<T> typeRef,
        final int... responseCodes) throws AproxClientException {
    connect();//from w  w w.  ja v a2  s  .  c o m

    HttpPost post = null;
    CloseableHttpResponse response = null;
    CloseableHttpClient client = null;
    try {
        client = newClient();
        post = newJsonPost(buildUrl(baseUrl, path));

        post.setEntity(new StringEntity(objectMapper.writeValueAsString(value)));

        response = client.execute(post);

        final StatusLine sl = response.getStatusLine();
        if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
            throw new AproxClientException("Error retrieving %s from: %s. Status was: %d %s (%s)",
                    typeRef.getType(), path, sl.getStatusCode(), sl.getReasonPhrase(), sl.getProtocolVersion());
        }

        final String json = entityToString(response);
        return objectMapper.readValue(json, typeRef);
    } catch (final IOException e) {
        throw new AproxClientException("AProx request failed: %s", e, e.getMessage());
    } finally {
        cleanupResources(post, response, client);
    }
}

From source file:org.commonjava.propulsor.client.http.ClientHttpSupport.java

public <T> T get(final String path, final TypeReference<T> typeRef) throws ClientHttpException {
    connect();//from   w w w .  j a  v  a  2  s .  com

    HttpGet request = null;
    CloseableHttpResponse response = null;
    CloseableHttpClient client = null;
    try {
        client = newClient();
        request = newJsonGet(buildUrl(baseUrl, path));
        response = client.execute(request);
        final StatusLine sl = response.getStatusLine();
        if (sl.getStatusCode() != 200) {
            if (sl.getStatusCode() == 404) {
                return null;
            }

            throw new ClientHttpException(sl.getStatusCode(), "Error retrieving %s from: %s.\n%s",
                    typeRef.getType(), path, new ClientHttpResponseErrorDetails(response));
        }

        final String json = entityToString(response);
        final T value = objectMapper.readValue(json, typeRef);

        return value;
    } catch (final IOException e) {
        throw new ClientHttpException("Client request failed: %s", e, e.getMessage());
    } finally {
        cleanupResources(request, response, client);
    }
}

From source file:org.commonjava.propulsor.client.http.ClientHttpSupport.java

public <T> T postWithResponse(final String path, final Object value, final TypeReference<T> typeRef,
        final int... responseCodes) throws ClientHttpException {
    checkRequestValue(value);/*from w  ww  . j av  a  2s  .  c o  m*/

    connect();

    HttpPost post = null;
    CloseableHttpResponse response = null;
    CloseableHttpClient client = null;
    try {
        client = newClient();
        post = newJsonPost(buildUrl(baseUrl, path));

        post.setEntity(new StringEntity(objectMapper.writeValueAsString(value), APPLICATION_JSON));

        response = client.execute(post);

        final StatusLine sl = response.getStatusLine();
        if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
            throw new ClientHttpException(sl.getStatusCode(), "Error retrieving %s from: %s.\n%s",
                    typeRef.getType(), path, new ClientHttpResponseErrorDetails(response));
        }

        final String json = entityToString(response);
        return objectMapper.readValue(json, typeRef);
    } catch (final IOException e) {
        throw new ClientHttpException("Client request failed: %s", e, e.getMessage());
    } finally {
        cleanupResources(post, response, client);
    }
}

From source file:org.commonjava.indy.client.core.IndyClientHttp.java

public <T> T get(final String path, final TypeReference<T> typeRef) throws IndyClientException {
    connect();//from  w  ww  .ja v a 2 s.  co m

    HttpGet request = null;
    CloseableHttpResponse response = null;
    CloseableHttpClient client = null;
    try {
        client = newClient();
        request = newJsonGet(buildUrl(baseUrl, path));
        response = client.execute(request, newContext());
        final StatusLine sl = response.getStatusLine();
        if (sl.getStatusCode() != 200) {
            if (sl.getStatusCode() == 404) {
                return null;
            }

            throw new IndyClientException(sl.getStatusCode(), "Error retrieving %s from: %s.\n%s",
                    typeRef.getType(), path, new IndyResponseErrorDetails(response));
        }

        final String json = entityToString(response);
        final T value = objectMapper.readValue(json, typeRef);

        return value;
    } catch (final IOException e) {
        throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
    } finally {
        cleanupResources(request, response, client);
    }
}

From source file:org.commonjava.indy.client.core.IndyClientHttp.java

public <T> T postWithResponse(final String path, final Object value, final TypeReference<T> typeRef,
        final int... responseCodes) throws IndyClientException {
    checkRequestValue(value);/*from  w w  w  .ja va 2 s  .  c  o m*/

    connect();

    HttpPost post = null;
    CloseableHttpResponse response = null;
    CloseableHttpClient client = null;
    try {
        client = newClient();
        post = newJsonPost(buildUrl(baseUrl, path));

        post.setEntity(new StringEntity(objectMapper.writeValueAsString(value)));

        response = client.execute(post, newContext());

        final StatusLine sl = response.getStatusLine();
        if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
            throw new IndyClientException(sl.getStatusCode(), "Error retrieving %s from: %s.\n%s",
                    typeRef.getType(), path, new IndyResponseErrorDetails(response));
        }

        final String json = entityToString(response);
        return objectMapper.readValue(json, typeRef);
    } catch (final IOException e) {
        throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
    } finally {
        cleanupResources(post, response, client);
    }
}