Search in sources :

Example 1 with TypeParameter

use of com.google.common.reflect.TypeParameter in project core-java by SpineEventEngine.

the class Types method listTypeOf.

/**
     * Creates the parametrized {@code Type} of the list.
     *
     * @param elementClass the class of the list elements
     * @param <T>          the type of the elements in this list
     * @return the type of the list
     */
public static <T> Type listTypeOf(Class<T> elementClass) {
    checkNotNull(elementClass);
    final Type type = new TypeToken<List<T>>() {
    }.where(new TypeParameter<T>() {
    }, elementClass).getType();
    return type;
}
Also used : Type(java.lang.reflect.Type) TypeParameter(com.google.common.reflect.TypeParameter) TypeToken(com.google.common.reflect.TypeToken)

Example 2 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, Class<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).getType();
    return new JsonCodec<>(createObjectMapper(), mapType);
}
Also used : Type(java.lang.reflect.Type) TypeParameter(com.google.common.reflect.TypeParameter) Map(java.util.Map)

Example 3 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(Class<T> type) {
    requireNonNull(type, "type is null");
    Type listType = new TypeToken<List<T>>() {
    }.where(new TypeParameter<T>() {
    }, type).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 4 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 5 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)

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