public static void main(String[] args) { Logger LOG = Logger.getLogger(IgnoredMediaTypes.class); LOG.info(getVendorString("foo+json")); LOG.info(getSubtype("foo+json")); }
/** * */ @Override protected boolean isReadWritable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return (type.isAnnotationPresent(XmlType.class) && !type.isAnnotationPresent(XmlRootElement.class)) && (FindAnnotation.findAnnotation(type, annotations, DoNotUseJAXBProvider.class) == null) && !IgnoredMediaTypes.ignored(type, annotations, mediaType); }
public static boolean ignored(Class<?> type, Annotation[] annotations, MediaType mediaType) { IgnoreMediaTypes ignore = FindAnnotation.findAnnotation(type, annotations, IgnoreMediaTypes.class); if (ignore == null) return false; for (String mime : ignore.value()) { if (compare(mediaType, mime)) return true; } return false; }
private static boolean compare(MediaType mediaType, String mime) { MediaType mt = MediaType.valueOf(mime); if (mt.isWildcardType() || mediaType.isWildcardType()) return true; if (!mediaType.getType().equals(mt.getType())) return false; if (mt.isWildcardSubtype() || mt.isWildcardSubtype()) return true; if (mt.getSubtype().startsWith("*+")) { String compare = getSubtype(mt.getSubtype()); String compare2 = getSubtype(mediaType.getSubtype()); return compare.equals(compare2); } else if (mt.getSubtype().endsWith("+*")) { String compare = getVendorString(mt.getSubtype()); String compare2 = getVendorString(mediaType.getSubtype()); return compare.equals(compare2); } else { return mt.getSubtype().equals(mediaType.getSubtype()); } }
@Override protected boolean isReadWritable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return type.isAnnotationPresent(XmlRootElement.class) && (FindAnnotation.findAnnotation(type, annotations, DoNotUseJAXBProvider.class) == null) && !IgnoredMediaTypes.ignored(type, annotations, mediaType); }
@Override protected boolean isReadWritable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return (type.isAnnotationPresent(XmlSeeAlso.class) && !type.isAnnotationPresent(XmlRootElement.class) && !type.isAnnotationPresent(XmlType.class)) && (FindAnnotation.findAnnotation(type, annotations, DoNotUseJAXBProvider.class) == null) && !IgnoredMediaTypes.ignored(type, annotations, mediaType); }
protected boolean isWrapped(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if ((Collection.class.isAssignableFrom(type) || type.isArray()) && genericType != null) { Class<?> baseType = Types.getCollectionBaseType(type, genericType); if (baseType == null) return false; baseType = XmlAdapterWrapper.xmlAdapterValueType(baseType, annotations); return (baseType.isAnnotationPresent(XmlRootElement.class) || baseType.isAnnotationPresent(XmlType.class) || baseType.isAnnotationPresent(XmlSeeAlso.class) || JAXBElement.class.equals(baseType)) && (FindAnnotation.findAnnotation(baseType, annotations, DoNotUseJAXBProvider.class) == null) && !IgnoredMediaTypes.ignored(baseType, annotations, mediaType); } return false; }
protected boolean isWrapped(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (Map.class.isAssignableFrom(type) && genericType != null) { Class<?> keyType = Types.getMapKeyType(genericType); if (keyType == null) return false; if (!CharSequence.class.isAssignableFrom(keyType) && !Number.class.isAssignableFrom(keyType)) return false; Class<?> valueType = Types.getMapValueType(genericType); if (valueType == null) return false; valueType = XmlAdapterWrapper.xmlAdapterValueType(valueType, annotations); return (valueType.isAnnotationPresent(XmlRootElement.class) || valueType.isAnnotationPresent(XmlType.class) || valueType.isAnnotationPresent(XmlSeeAlso.class) || JAXBElement.class.equals(valueType)) && (FindAnnotation.findAnnotation(valueType, annotations, DoNotUseJAXBProvider.class) == null) && !IgnoredMediaTypes.ignored(valueType, annotations, mediaType); } return false; }