use of com.google.api.server.spi.config.Transformer in project endpoints-java by cloudendpoints.
the class Serializers method getSerializerClasses.
public static List<Class<? extends Transformer<?, ?>>> getSerializerClasses(TypeToken<?> type, @Nullable final ApiSerializationConfig config) {
if (type == null) {
return Collections.emptyList();
}
List<Class<? extends Transformer<?, ?>>> allParentSerializers = Lists.newArrayList();
List<TypeToken<?>> serializedTypes = Lists.newArrayList();
for (TypeToken<?> typeToken : type.getTypes()) {
ApiTransformer apiSerialization = typeToken.getRawType().getAnnotation(ApiTransformer.class);
if (isSupertypeOf(typeToken, serializedTypes)) {
continue;
}
if (apiSerialization != null) {
allParentSerializers.add(apiSerialization.value());
serializedTypes.add(typeToken);
} else if (config != null) {
ApiSerializationConfig.SerializerConfig serializerConfig = config.getSerializerConfig(typeToken);
if (serializerConfig != null) {
allParentSerializers.add(serializerConfig.getSerializer());
serializedTypes.add(typeToken);
}
}
}
return allParentSerializers;
}
use of com.google.api.server.spi.config.Transformer in project endpoints-java by cloudendpoints.
the class ApiAnnotationIntrospector method getSchemaType.
/**
* Gets the schema type for a type. The schema type is identical to the original type if
* there is no matching {@link com.google.api.server.spi.config.ApiTransformer} annotation for
* the type. If there is a {@link com.google.api.server.spi.config.ResourceTransformer} installed,
* the source type determines schema, not the output map.
*/
public static TypeToken<?> getSchemaType(TypeToken<?> type, ApiConfig config) {
Type rawType = type.getType();
if (rawType instanceof Class || rawType instanceof ParameterizedType) {
List<Class<? extends Transformer<?, ?>>> serializers = Serializers.getSerializerClasses(type, config.getSerializationConfig());
if (!serializers.isEmpty() && !(ResourceTransformer.class.isAssignableFrom(serializers.get(0)))) {
TypeToken<?> sourceType = Serializers.getSourceType(serializers.get(0));
TypeToken<?> serializedType = Serializers.getTargetType(serializers.get(0));
Preconditions.checkArgument(sourceType.isSupertypeOf(type), "Serializer specified for %s, but only serializes for %s: %s", type, sourceType, serializers.get(0));
Preconditions.checkArgument(serializedType != null, "Couldn't find Serializer interface in serializer for %s: %s", type, serializers.get(0));
return serializedType;
}
}
return type;
}
use of com.google.api.server.spi.config.Transformer in project endpoints-java by cloudendpoints.
the class ApiAnnotationIntrospector method findSerializerInstance.
@Nullable
private Transformer<?, ?> findSerializerInstance(Annotated a) {
if (a instanceof AnnotatedClass) {
AnnotatedClass clazz = (AnnotatedClass) a;
List<Class<? extends Transformer<?, ?>>> serializerClasses = Serializers.getSerializerClasses(clazz.getRawType(), config);
if (!serializerClasses.isEmpty()) {
return Serializers.instantiate(serializerClasses.get(0), TypeToken.of(a.getRawType()));
}
}
return null;
}
use of com.google.api.server.spi.config.Transformer in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReader method readEndpointClass.
@SuppressWarnings("unchecked")
private boolean readEndpointClass(ApiConfig config, Class<?> endpointClass, Annotation api, Annotation apiClass, @Nullable Class<?> cycleCheck) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, CyclicApiInheritanceException {
cycleCheck = checkForInheritanceCycle(endpointClass, cycleCheck);
boolean hasAnnotation = api != null;
Class<?> inheritanceSource = determineInheritanceSource(endpointClass);
if (inheritanceSource != null) {
Annotation superApi = getDeclaredAnnotation(inheritanceSource, annotationTypes.get("Api"));
Annotation superApiClass = getDeclaredAnnotation(inheritanceSource, annotationTypes.get("ApiClass"));
hasAnnotation |= readEndpointClass(config, inheritanceSource, superApi, superApiClass, cycleCheck);
}
if (api != null) {
readApi(new ApiAnnotationConfig(config), api);
readApiAuth(new ApiAuthAnnotationConfig(config.getAuthConfig()), (Annotation) getAnnotationProperty(api, "auth"));
readApiFrontendLimits(new ApiFrontendLimitsAnnotationConfig(config.getFrontendLimitsConfig()), (Annotation) getAnnotationProperty(api, "frontendLimits"));
readApiCacheControl(new ApiCacheControlAnnotationConfig(config.getCacheControlConfig()), (Annotation) getAnnotationProperty(api, "cacheControl"));
readApiNamespace(new ApiNamespaceAnnotationConfig(config.getNamespaceConfig()), (Annotation) getAnnotationProperty(api, "namespace"));
readSerializers(config.getSerializationConfig(), (Class<? extends Transformer<?, ?>>[]) getAnnotationProperty(api, "transformers"));
}
if (apiClass != null) {
readApiClass(new ApiClassAnnotationConfig(config.getApiClassConfig()), apiClass);
}
return hasAnnotation;
}
Aggregations