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 interface
This is to allow customized JAXB collections checking. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Class<?>[]
private static final AbstractCollectionJaxbProvider.JaxbTypeChecker
private final NounInflector
private static final Logger
Fields 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 String
convertToXmlName
(String name) private static Object
createArray
(Collection<?> collection, Class componentType) protected 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, javax.ws.rs.core.MediaType mediaType, Unmarshaller unmarshaller, InputStream entityStream) Get theXMLStreamReader
for unmarshalling.boolean
isReadable
(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) boolean
isWriteable
(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) 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) private static boolean
verifyArrayType
(Class type) 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) private static boolean
verifyGenericType
(Type genericType) 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, 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 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) 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
-
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 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
-
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
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.
-