List of usage examples for com.fasterxml.jackson.core.type TypeReference getType
public Type getType()
From source file:com.basho.riak.client.api.cap.ConflictResolverFactory.java
public <T> void unregisterConflictResolver(TypeReference<T> typeReference) { resolverInstances.remove(typeReference.getType()); }
From source file:com.okta.sdk.framework.JsonApiClient.java
@Override protected <T> T unmarshall(HttpResponse response, TypeReference<T> clazz) throws IOException { if (response.getEntity() == null || clazz.getType().equals(Void.class)) { EntityUtils.consume(response.getEntity()); return null; }/* ww w .ja v a 2 s . co m*/ InputStream inputStream = response.getEntity().getContent(); JsonParser parser = objectMapper.getFactory().createParser(inputStream); T toReturn = parser.readValueAs(clazz); EntityUtils.consume(response.getEntity()); return toReturn; }
From source file:com.basho.riak.client.api.cap.ConflictResolverFactory.java
/** * Return the ConflictResolver for the given class. * <p>//w w w.j av a 2s .c o m * If no ConflictResolver is registered for the provided class, an instance of the * {@link com.basho.riak.client.cap.DefaultResolver} is returned. * </p> * @param <T> The type being resolved * @param clazz the class of the type being resolved * @return The conflict resolver for the type. * @throws UnresolvedConflictException */ @SuppressWarnings("unchecked") private <T> ConflictResolver<T> getConflictResolver(Type type, TypeReference<T> typeReference) { type = type != null ? type : typeReference.getType(); ConflictResolver<T> resolver = (ConflictResolver<T>) resolverInstances.get(type); if (resolver == null) { // Cache this? resolver = (ConflictResolver<T>) new DefaultResolver<T>(); } return resolver; }
From source file:com.basho.riak.client.api.convert.ConverterFactory.java
/** * Unregister a converter./*from w w w. j a va 2 s .com*/ * @param <T> The type * @param typeReference the TypeReference for the class being converted. */ public <T> void unregisterConverterForClass(TypeReference<T> typeReference) { Type t = typeReference.getType(); converterInstances.remove(t); }
From source file:com.basho.riak.client.api.cap.ConflictResolverFactory.java
public <T> void registerConflictResolver(TypeReference<T> typeReference, ConflictResolver<T> resolver) { resolverInstances.put(typeReference.getType(), resolver); }
From source file:com.basho.riak.client.api.convert.ConverterFactory.java
/** * Register a converter for the supplied class. * <p>/* w w w . ja v a 2 s . co m*/ * This instance be re-used for every conversion. * </p> * @param <T> The type being converted * @param typeReference the TypeReference for the class being converted. * @param converter an instance of Converter */ public <T> void registerConverterForClass(TypeReference<T> typeReference, Converter<T> converter) { Type t = typeReference.getType(); converterInstances.put(t, converter); }
From source file:com.basho.riak.client.api.convert.ConverterFactory.java
@SuppressWarnings("unchecked") private <T> Converter<T> getConverter(Type type, TypeReference<T> typeReference) { type = type != null ? type : typeReference.getType(); Converter<T> converter;/* ww w . j a v a 2 s . c o m*/ converter = (Converter<T>) converterInstances.get(type); if (converter == null) { if (typeReference != null) { // Should we cache this? converter = new JSONConverter<T>(typeReference); } else { converter = new JSONConverter<T>(type); } } return converter; }
From source file:kirchnerei.glatteis.json.JsonConvertService.java
public <T> T fromString(String text, TypeReference<T> ref) { try {//from w ww .ja v a2 s .c o m return mapper.readValue(text, ref); } catch (Exception e) { throw new JsonConvertException(e, "covert into the type '%s' is failed'", ref == null ? "null" : ref.getType()); } }
From source file:com.blacklocus.jres.request.JsonSerializableTest.java
/** * Serializes to json, serializes back to object, serializes back to json - the two json strings should match. * Depends on equals being correctly implemented and exhaustive of all core parameters of the request. * <p/>/* w w w. j av a 2 s.c om*/ * Notes that the bulkable class has been included in {@link #testRequestObjectsSerializable()} */ @SuppressWarnings("unchecked") <T extends JresBulkable> void forSerial(T bulkableRequest, TypeReference<T> typeReference) { T roundTrip = ObjectMappers.fromJson(ObjectMappers.toJson(bulkableRequest), typeReference); Assert.assertEquals(bulkableRequest, roundTrip); BULKABLE_CLASSES_SERIAL.add((Class<? extends JresBulkable>) ObjectMappers.NORMAL.getTypeFactory() .constructType(typeReference.getType()).getRawClass()); }
From source file:org.opendaylight.defense4all.odl.controller.Connector.java
protected synchronized <T> T getFromController(String urlPrefix, TypeReference<?> typeRef, JsonPreprocessor preProcessor) throws RestClientException { T t;/* ww w . j ava 2 s .co m*/ try { String url = mkUrl(urlPrefix); log.debug("Caller: " + getMethodName(2) + " Class:" + typeRef.getType().toString() + " Invoking restTemplate.getForObject" + "Calling - URL: " + url + " JSON: "); String result = //restTemplate.getForObject(url, String.class); restCallWithAutorization(url, "admin", "admin"); if (result == null) return null; // Don't print it to log - it may contain non-printable chars // log.debug("Caller: "+getMethodName(2)+" Class:"+typeRef.getType().toString()+" URL: "+url+" JSON: "+result.toString()); if (preProcessor != null) result = preProcessor.preProcess(result); t = fasterxmlObjMapper.readValue(result, typeRef); } catch (Throwable e) { log.error("Failed to get from controller " + odlOFC.hostname, e); throw new RestClientException("Failed to get from controller " + odlOFC.hostname, e); } return t; }