Class AbstractCollectionJaxbProvider
- All Implemented Interfaces:
javax.ws.rs.ext.MessageBodyReader<Object>,javax.ws.rs.ext.MessageBodyWriter<Object>
- Direct Known Subclasses:
XmlCollectionJaxbProvider
T[], Collection<T>,
and its subtypes as long as they have the public default constructor or
are interfaces implemented by one the following classes:
T must be a JAXB type annotated with XmlRootElement.
Implementing classes may extend this class to provide specific marshalling and unmarshalling behaviour.
When unmarshalling a UnmarshalException will result in a
WebApplicationException being thrown with a status of 400
(Client error), and a JAXBException will result in a
WebApplicationException being thrown with a status of 500
(Internal Server error).
When marshalling a JAXBException will result in a
WebApplicationException being thrown with a status of 500
(Internal Server error).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis is to allow customized JAXB collections checking. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Class<?>[]private static final AbstractCollectionJaxbProvider.JaxbTypeCheckerprivate final NounInflectorprivate static final LoggerFields inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
UTF8 -
Constructor Summary
ConstructorsConstructorDescriptionAbstractCollectionJaxbProvider(javax.ws.rs.ext.Providers ps) AbstractCollectionJaxbProvider(javax.ws.rs.ext.Providers ps, javax.ws.rs.core.MediaType mt) -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringconvertToXmlName(String name) private static ObjectcreateArray(Collection<?> collection, Class componentType) protected static ClassgetElementClass(Class<?> type, Type genericType) protected static StringgetElementName(Class<?> elementType) Get the element name for a given Java type.protected final StringgetRootElementName(Class<?> elementType) Construct the name of the root element from it's Java type name.protected abstract XMLStreamReadergetXMLStreamReader(Class<?> elementType, javax.ws.rs.core.MediaType mediaType, Unmarshaller unmarshaller, InputStream entityStream) Get theXMLStreamReaderfor unmarshalling.booleanisReadable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) booleanisWriteable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) final ObjectreadFrom(Class<Object> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String, String> httpHeaders, InputStream inputStream) private static booleanverifyArrayType(Class type) static booleanverifyArrayType(Class type, AbstractCollectionJaxbProvider.JaxbTypeChecker checker) The method could be used to check if given type is an array of JAXB beans.static booleanverifyCollectionSubclass(Class<?> type) private static booleanverifyGenericType(Type genericType) static booleanverifyGenericType(Type genericType, AbstractCollectionJaxbProvider.JaxbTypeChecker checker) The method could be used to check if given type is a collection of JAXB beans.abstract voidwriteCollection(Class<?> elementType, Collection<?> t, javax.ws.rs.core.MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) Write a collection of JAXB objects as child elements of the root element.final voidwriteTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) Methods inherited from class org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider
getMarshaller, getSAXSource, getStoredJaxbContext, getUnmarshaller, isFormattedOutput, isSupported, isXmlRootElementProcessing, setConfiguration, setHeaderMethods inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
getCharset, getSize, readFromAsString, writeTo, writeTo, writeToAsString
-
Field Details
-
LOGGER
-
DEFAULT_IMPLS
-
DefaultJaxbTypeCHECKER
-
inflector
-
-
Constructor Details
-
AbstractCollectionJaxbProvider
public AbstractCollectionJaxbProvider(javax.ws.rs.ext.Providers ps) -
AbstractCollectionJaxbProvider
public AbstractCollectionJaxbProvider(javax.ws.rs.ext.Providers ps, javax.ws.rs.core.MediaType mt)
-
-
Method Details
-
isReadable
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) -
isWriteable
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) -
verifyCollectionSubclass
-
verifyArrayType
-
verifyArrayType
public static boolean verifyArrayType(Class type, AbstractCollectionJaxbProvider.JaxbTypeChecker checker) The method could be used to check if given type is an array of JAXB beans. It allows customizing the "is this a JAXB bean?" part.- Parameters:
type- the array to be checkedchecker- allows JAXB bean check customization- Returns:
- true if given type is an array of JAXB beans
-
verifyGenericType
-
verifyGenericType
public static boolean verifyGenericType(Type genericType, AbstractCollectionJaxbProvider.JaxbTypeChecker checker) The method could be used to check if given type is a collection of JAXB beans. It allows customizing the "is this a JAXB bean?" part.- Parameters:
genericType- the type to be checkedchecker- allows JAXB bean check customization- Returns:
- true if given type is a collection of JAXB beans
-
writeTo
public final void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException- Throws:
IOException
-
writeCollection
public abstract void writeCollection(Class<?> elementType, Collection<?> t, javax.ws.rs.core.MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException, IOException Write a collection of JAXB objects as child elements of the root element.- Parameters:
elementType- the element type in the collection.t- the collection to marshallmediaType- the media typec- the charsetm- the marshallerentityStream- the output stream to marshall the collection- Throws:
JAXBException- in case the marshalling of element collection fails.IOException- in case of any other I/O error while marshalling the collection of JAXB objects.
-
readFrom
public final Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException- Throws:
IOException
-
createArray
-
getXMLStreamReader
protected abstract XMLStreamReader getXMLStreamReader(Class<?> elementType, javax.ws.rs.core.MediaType mediaType, Unmarshaller unmarshaller, InputStream entityStream) throws XMLStreamException Get theXMLStreamReaderfor unmarshalling.- Parameters:
elementType- the individual element type.mediaType- the media type.unmarshaller- the unmarshaller as a carrier of possible config options.entityStream- the input stream.- Returns:
- the XMLStreamReader.
- Throws:
XMLStreamException- in caseXMLStreamReaderretrieval fails.
-
getElementClass
-
convertToXmlName
-
getRootElementName
Construct the name of the root element from it's Java type name.- Parameters:
elementType- element Java type.- Returns:
- constructed root element name for a given element Java type.
-
getElementName
Get the element name for a given Java type.In case the element is annotated with a
XmlRootElementannotation and thespecified element nameis not default, the method returns the specified element name in the annotation. Otherwise, the method returns the name of the element class instead.- Parameters:
elementType- element Java type.- Returns:
- element name for a given element Java type.
-