use of com.google.common.reflect.TypeParameter in project airlift by airlift.
the class JsonCodecFactory method listJsonCodec.
public <T> JsonCodec<List<T>> listJsonCodec(JsonCodec<T> type) {
requireNonNull(type, "type is null");
Type listType = new TypeToken<List<T>>() {
}.where(new TypeParameter<T>() {
}, type.getTypeToken()).getType();
return new JsonCodec<>(createObjectMapper(), listType);
}
use of com.google.common.reflect.TypeParameter in project airlift by airlift.
the class JsonCodecFactory method mapJsonCodec.
public <K, V> JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, JsonCodec<V> valueType) {
requireNonNull(keyType, "keyType is null");
requireNonNull(valueType, "valueType is null");
Type mapType = new TypeToken<Map<K, V>>() {
}.where(new TypeParameter<K>() {
}, keyType).where(new TypeParameter<V>() {
}, valueType.getTypeToken()).getType();
return new JsonCodec<>(createObjectMapper(), mapType);
}
use of com.google.common.reflect.TypeParameter in project core-java by SpineEventEngine.
the class Types method mapTypeOf.
/**
* Creates the parametrized {@code Type} of the map.
*
* @param keyClass the class of keys are maintained by this map
* @param valueClass the class of mapped values
* @param <K> the type of keys are maintained by this map
* @param <V> the type of the values stored in this map
* @return the type of the map
*/
public static <K, V> Type mapTypeOf(Class<K> keyClass, Class<V> valueClass) {
checkNotNull(keyClass);
checkNotNull(valueClass);
final Type type = new TypeToken<Map<K, V>>() {
}.where(new TypeParameter<K>() {
}, keyClass).where(new TypeParameter<V>() {
}, valueClass).getType();
return type;
}
use of com.google.common.reflect.TypeParameter in project airlift by airlift.
the class JsonCodec method mapJsonCodec.
public static <K, V> JsonCodec<Map<K, V>> mapJsonCodec(Class<K> keyType, JsonCodec<V> valueType) {
requireNonNull(keyType, "keyType is null");
requireNonNull(valueType, "valueType is null");
Type mapType = new TypeToken<Map<K, V>>() {
}.where(new TypeParameter<K>() {
}, keyType).where(new TypeParameter<V>() {
}, valueType.getTypeToken()).getType();
return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), mapType);
}
use of com.google.common.reflect.TypeParameter in project airlift by airlift.
the class JsonCodec method listJsonCodec.
public static <T> JsonCodec<List<T>> listJsonCodec(JsonCodec<T> type) {
requireNonNull(type, "type is null");
Type listType = new TypeToken<List<T>>() {
}.where(new TypeParameter<T>() {
}, type.getTypeToken()).getType();
return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), listType);
}
Aggregations