use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.
the class ImmutableListSerializerExtension method getSerializer.
@Override
public Optional<Serializer> getSerializer(TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) {
if (!isImmutableList(typeMirror)) {
return Optional.empty();
}
// Extract the T of ImmutableList<T>.
TypeMirror containedType = getContainedType(typeMirror);
Serializer containedTypeSerializer = factory.getSerializer(containedType);
// We don't need this serializer if the T of ImmutableList<T> is serializable.
if (containedTypeSerializer.isIdentity()) {
return Optional.empty();
}
return Optional.of(new ImmutableListSerializer(containedTypeSerializer, factory, processingEnv));
}
use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.
the class OptionalSerializerExtension method getSerializer.
/**
* Creates a {@link Serializer} that supports {@link Optional} types.
*/
@Override
public Optional<Serializer> getSerializer(TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) {
if (!isOptional(typeMirror)) {
return Optional.empty();
}
// Extract the T of Optional<T>.
TypeMirror containedType = getContainedType(typeMirror);
Serializer containedTypeSerializer = factory.getSerializer(containedType);
return Optional.of(new OptionalSerializer(containedTypeSerializer));
}
use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.
the class ImmutableMapSerializerExtension method getSerializer.
@Override
public Optional<Serializer> getSerializer(TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) {
if (!isImmutableMap(typeMirror)) {
return Optional.empty();
}
// Extract the K, V of ImmutableMap<K, V>.
TypeMirror keyType = getKeyType(typeMirror);
TypeMirror valueType = getValueType(typeMirror);
Serializer keyTypeSerializer = factory.getSerializer(keyType);
Serializer valueTypeSerializer = factory.getSerializer(valueType);
// We don't need this serializer if the K and V of ImmutableMap<K, V> are serializable.
if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) {
return Optional.empty();
}
return Optional.of(new ImmutableMapSerializer(keyType, valueType, keyTypeSerializer, valueTypeSerializer, factory, processingEnv));
}
use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.
the class ImmutableListSerializerExtensionTest method getSerializer_nonImmutableList_emptyReturned.
@Test
public void getSerializer_nonImmutableList_emptyReturned() {
TypeMirror typeMirror = typeMirrorOf(String.class);
Optional<Serializer> actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment);
assertThat(actualSerializer).isEmpty();
}
use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.
the class ImmutableListSerializerExtensionTest method proxyFieldType.
@Test
public void proxyFieldType() {
TypeMirror typeMirror = declaredTypeOf(ImmutableList.class, Integer.class);
Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
TypeMirror actualTypeMirror = serializer.proxyFieldType();
assertThat(typeUtils.isSameType(actualTypeMirror, typeMirror)).isTrue();
}
Aggregations