@Override public MediaTypeDescriptor findMediaTypeDescriptor(String mediaType, DecoratedTypeMirror typeMirror) { if (mediaType == null) { return null; } //if it's a wildcard, we'll return an implicit descriptor. if (mediaType.equals("*/*") || mediaType.equals("application/*")) { mediaType = "application/json"; } if (mediaType.endsWith("/json") || mediaType.endsWith("+json")) { typeMirror = this.context.resolveSyntheticType(typeMirror); DataTypeReference typeReference = findDataTypeReference(typeMirror); return typeReference == null ? null : new MediaTypeDescriptorImpl(mediaType, typeReference); } else { return null; } }
@Override public MediaTypeDescriptor findMediaTypeDescriptor(String mediaType, DecoratedTypeMirror typeMirror) { if (mediaType == null) { return null; } //if it's a wildcard, we'll return an implicit descriptor. if (mediaType.equals("*/*") || mediaType.equals("application/*")) { mediaType = "application/json"; } if (mediaType.endsWith("/json") || mediaType.endsWith("+json")) { typeMirror = this.context.resolveSyntheticType(typeMirror); DataTypeReference typeReference = findDataTypeReference(typeMirror); return typeReference == null ? null : new MediaTypeDescriptorImpl(mediaType, typeReference); } else { return null; } }
@Override public void addDataTypeDefinitions(TypeMirror type, Set<String> declaredMediaTypes, LinkedList<Element> contextStack) { if (MediaTypeUtils.isJsonCompatible(declaredMediaTypes)) { type = this.jacksonContext.resolveSyntheticType((DecoratedTypeMirror) type); this.jacksonContext.addReferencedTypeDefinitions(type, contextStack); } else { debug("Element %s is NOT to be added as a Jackson data type because %s doesn't seem to include JSON.", type, declaredMediaTypes); } }
@Override public void addDataTypeDefinitions(TypeMirror type, Set<String> declaredMediaTypes, LinkedList<Element> contextStack) { if (MediaTypeUtils.isJsonCompatible(declaredMediaTypes)) { type = this.jacksonContext.resolveSyntheticType((DecoratedTypeMirror) type); this.jacksonContext.addReferencedTypeDefinitions(type, contextStack); } else { debug("Element %s is NOT to be added as a Jackson data type because %s doesn't seem to include JSON.", type, declaredMediaTypes); } }
private void gatherInterfaces(TypeElement clazz, Set<DataTypeReference> interfaces) { if (clazz == null) { return; } if (clazz.getQualifiedName().contentEquals(Object.class.getName())) { return; } List<? extends TypeMirror> ifaces = clazz.getInterfaces(); for (TypeMirror iface : ifaces) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) iface; decorated = this.typeDefinition.getContext().resolveSyntheticType(decorated); TypeDefinition typeDefinition = this.typeDefinition.getContext().findTypeDefinition(((DeclaredType) decorated).asElement()); if (typeDefinition != null) { interfaces.add(new DataTypeReferenceImpl(new JsonClassType(typeDefinition), registrationContext)); } } TypeMirror superclass = clazz.getSuperclass(); if (superclass instanceof DeclaredType) { gatherInterfaces((TypeElement) ((DeclaredType) superclass).asElement(), interfaces); } }
private void gatherInterfaces(TypeElement clazz, Set<DataTypeReference> interfaces) { if (clazz == null) { return; } if (clazz.getQualifiedName().contentEquals(Object.class.getName())) { return; } List<? extends TypeMirror> ifaces = clazz.getInterfaces(); for (TypeMirror iface : ifaces) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) iface; decorated = this.typeDefinition.getContext().resolveSyntheticType(decorated); TypeDefinition typeDefinition = this.typeDefinition.getContext().findTypeDefinition(((DeclaredType) decorated).asElement()); if (typeDefinition != null) { interfaces.add(new DataTypeReferenceImpl(new JsonClassType(typeDefinition), registrationContext)); } } TypeMirror superclass = clazz.getSuperclass(); if (superclass instanceof DeclaredType) { gatherInterfaces((TypeElement) ((DeclaredType) superclass).asElement(), interfaces); } }
/** * The type of the accessor. * * @return The type of the accessor. */ public DecoratedTypeMirror getAccessorType() { DecoratedTypeMirror accessorType = (DecoratedTypeMirror) asType(); accessorType = OptionalUtils.stripOptional(accessorType, this.context.getContext().getProcessingEnvironment()); accessorType = this.context.resolveSyntheticType(accessorType); DecoratedDeclaredType normalizedCollection = JacksonUtil.getNormalizedCollection(accessorType, this.context.getContext().getProcessingEnvironment()); if (normalizedCollection != null) { accessorType = normalizedCollection; } else { MapType mapType = MapType.findMapType(accessorType, this.context); if (mapType != null) { accessorType = mapType; } } return accessorType; }
/** * The type of the accessor. * * @return The type of the accessor. */ public DecoratedTypeMirror getAccessorType() { DecoratedTypeMirror accessorType = (DecoratedTypeMirror) asType(); accessorType = OptionalUtils.stripOptional(accessorType, this.context.getContext().getProcessingEnvironment()); accessorType = this.context.resolveSyntheticType(accessorType); DecoratedDeclaredType normalizedCollection = JacksonUtil.getNormalizedCollection(accessorType, this.context.getContext().getProcessingEnvironment()); if (normalizedCollection != null) { accessorType = normalizedCollection; } else { MapType mapType = MapType.findMapType(accessorType, this.context); if (mapType != null) { accessorType = mapType; } } return accessorType; }
public DecoratedTypeMirror resolveSyntheticType(DecoratedTypeMirror type) { if (type instanceof DeclaredType && !type.isCollection() && MapType.findMapType(type, this) == null) { if (!((DeclaredType) type).getTypeArguments().isEmpty()) { //if type arguments apply, create a new "synthetic" declared type that captures the type arguments. type = new ParameterizedJackson1DeclaredType((DeclaredType) type, getContext().getProcessingEnvironment()); } else if (type.isInterface()) { //if it's an interface, create a "synthetic" type that pretends like it's an abstract class. type = new InterfaceJackson1DeclaredType((DeclaredType) type, getContext().getProcessingEnvironment()); } } else if (type != null) { DecoratedTypeMirror componentType = TypeMirrorUtils.getComponentType(type, getContext().getProcessingEnvironment()); if (componentType != null) { DecoratedTypeMirror resolved = resolveSyntheticType(componentType); if (componentType != resolved) { return new SyntheticJackson1ArrayType(getContext().getProcessingEnvironment().getTypeUtils().getArrayType(resolved), resolved, getContext().getProcessingEnvironment()); } } } return type; }
public DecoratedTypeMirror resolveSyntheticType(DecoratedTypeMirror type) { if (type instanceof DeclaredType && !type.isCollection() && MapType.findMapType(type, this) == null) { if (!((DeclaredType) type).getTypeArguments().isEmpty()) { //if type arguments apply, create a new "synthetic" declared type that captures the type arguments. type = new ParameterizedJackson1DeclaredType((DeclaredType) type, getContext().getProcessingEnvironment()); } else if (type.isInterface()) { //if it's an interface, create a "synthetic" type that pretends like it's an abstract class. type = new InterfaceJackson1DeclaredType((DeclaredType) type, getContext().getProcessingEnvironment()); } } else if (type != null) { DecoratedTypeMirror componentType = TypeMirrorUtils.getComponentType(type, getContext().getProcessingEnvironment()); if (componentType != null) { DecoratedTypeMirror resolved = resolveSyntheticType(componentType); if (componentType != resolved) { return new SyntheticJackson1ArrayType(getContext().getProcessingEnvironment().getTypeUtils().getArrayType(resolved), resolved, getContext().getProcessingEnvironment()); } } } return type; }