Class AbstractCollectionJaxbProvider
- All Implemented Interfaces:
MessageBodyReader<Object>
,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).
- Author:
- Paul Sandoz, Martin Matula
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
This is to allow customized JAXB collections checking. -
Field Summary
Fields inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
UTF8
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractCollectionJaxbProvider
(Providers ps, Configuration config) AbstractCollectionJaxbProvider
(Providers ps, MediaType mt, Configuration config) -
Method Summary
Modifier and TypeMethodDescriptionprotected static Class
getElementClass
(Class<?> type, Type genericType) protected static String
getElementName
(Class<?> elementType) Get the element name for a given Java type.protected final String
getRootElementName
(Class<?> elementType) Construct the name of the root element from it's Java type name.protected abstract XMLStreamReader
getXMLStreamReader
(Class<?> elementType, MediaType mediaType, jakarta.xml.bind.Unmarshaller unmarshaller, InputStream entityStream) Get theXMLStreamReader
for unmarshalling.boolean
isReadable
(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) boolean
isWriteable
(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) final Object
readFrom
(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) static boolean
verifyArrayType
(Class type, AbstractCollectionJaxbProvider.JaxbTypeChecker checker) The method could be used to check if given type is an array of JAXB beans.static boolean
verifyCollectionSubclass
(Class<?> type) static boolean
verifyGenericType
(Type genericType, AbstractCollectionJaxbProvider.JaxbTypeChecker checker) The method could be used to check if given type is a collection of JAXB beans.abstract void
writeCollection
(Class<?> elementType, Collection<?> t, MediaType mediaType, Charset c, jakarta.xml.bind.Marshaller m, OutputStream entityStream) Write a collection of JAXB objects as child elements of the root element.final void
writeTo
(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) Methods inherited from class org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider
getMarshaller, getSAXSource, getStoredJaxbContext, getUnmarshaller, isFormattedOutput, isSupported, isXmlRootElementProcessing, setConfiguration, setHeader
Methods inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
getCharset, getSize, readFromAsString, writeTo, writeTo, writeToAsString
-
Constructor Details
-
AbstractCollectionJaxbProvider
-
AbstractCollectionJaxbProvider
-
-
Method Details
-
isReadable
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) -
isWriteable
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) -
verifyCollectionSubclass
-
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
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, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException- Throws:
IOException
-
writeCollection
public abstract void writeCollection(Class<?> elementType, Collection<?> t, MediaType mediaType, Charset c, jakarta.xml.bind.Marshaller m, OutputStream entityStream) throws jakarta.xml.bind.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:
jakarta.xml.bind.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, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException- Throws:
IOException
-
getXMLStreamReader
protected abstract XMLStreamReader getXMLStreamReader(Class<?> elementType, MediaType mediaType, jakarta.xml.bind.Unmarshaller unmarshaller, InputStream entityStream) throws XMLStreamException Get theXMLStreamReader
for 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 caseXMLStreamReader
retrieval fails.
-
getElementClass
-
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
XmlRootElement
annotation and thespecified element name
is 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.
-