Search in sources :

Example 6 with TypeParameter

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);
}
Also used : Type(java.lang.reflect.Type) TypeParameter(com.google.common.reflect.TypeParameter) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) TypeToken(com.google.common.reflect.TypeToken)

Example 7 with TypeParameter

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);
}
Also used : Type(java.lang.reflect.Type) TypeParameter(com.google.common.reflect.TypeParameter) Map(java.util.Map)

Example 8 with TypeParameter

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;
}
Also used : Type(java.lang.reflect.Type) TypeParameter(com.google.common.reflect.TypeParameter) Map(java.util.Map)

Example 9 with TypeParameter

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);
}
Also used : Type(java.lang.reflect.Type) JavaType(com.fasterxml.jackson.databind.JavaType) TypeParameter(com.google.common.reflect.TypeParameter) Map(java.util.Map)

Example 10 with TypeParameter

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);
}
Also used : Type(java.lang.reflect.Type) JavaType(com.fasterxml.jackson.databind.JavaType) TypeParameter(com.google.common.reflect.TypeParameter) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) TypeToken(com.google.common.reflect.TypeToken)

Aggregations

TypeParameter (com.google.common.reflect.TypeParameter)10 Type (java.lang.reflect.Type)10 TypeToken (com.google.common.reflect.TypeToken)5 Map (java.util.Map)5 JavaType (com.fasterxml.jackson.databind.JavaType)4 INDENT_OUTPUT (com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT)4