public MessageBodyWriter findWriter( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { for (MessageBodyWriter writer : messageBodyWriters) { if (writer.isWriteable(type, genericType, annotations, mediaType)) { return writer; } } return null; }
private static void checkJaxbType( Class<?> serviceClass, Class<?> type, Type genericType, ResourceTypes types, Annotation[] anns, MessageBodyWriter<?> jaxbWriter) { boolean isCollection = false; if (InjectionUtils.isSupportedCollectionOrArray(type)) { type = InjectionUtils.getActualType(genericType); isCollection = true; } if (type == Object.class && !(genericType instanceof Class)) { Type theType = InjectionUtils.processGenericTypeIfNeeded(serviceClass, Object.class, genericType); type = InjectionUtils.getActualType(theType); } if (type == null || InjectionUtils.isPrimitive(type) || JAXBElement.class.isAssignableFrom(type) || Response.class.isAssignableFrom(type) || type.isInterface()) { return; } MessageBodyWriter<?> writer = jaxbWriter; if (writer == null) { JAXBElementProvider<Object> defaultWriter = new JAXBElementProvider<Object>(); defaultWriter.setMarshallAsJaxbElement(true); defaultWriter.setXmlTypeAsJaxbElementOnly(true); writer = defaultWriter; } if (writer.isWriteable(type, type, anns, MediaType.APPLICATION_XML_TYPE)) { types.getAllTypes().put(type, type); Class<?> genCls = InjectionUtils.getActualType(genericType); if (genCls != type && genCls != null && genCls != Object.class && !InjectionUtils.isSupportedCollectionOrArray(genCls)) { types.getAllTypes().put(genCls, genCls); } XMLName name = AnnotationUtils.getAnnotation(anns, XMLName.class); QName qname = name != null ? JAXRSUtils.convertStringToQName(name.value()) : null; if (isCollection) { types.getCollectionMap().put(type, qname); } else { types.getXmlNameMap().put(type, qname); } } }