Class AbstractCollectionJaxbProvider
- java.lang.Object
-
- org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider<T>
-
- org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider<Object>
-
- org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider
-
- All Implemented Interfaces:
MessageBodyReader<Object>,MessageBodyWriter<Object>
- Direct Known Subclasses:
XmlCollectionJaxbProvider
public abstract class AbstractCollectionJaxbProvider extends AbstractJaxbProvider<Object>
An abstract provider forT[],Collection<T>, and its subtypes as long as they have the public default constructor or are interfaces implemented by one the following classes:Tmust be a JAXB type annotated withXmlRootElement.Implementing classes may extend this class to provide specific marshalling and unmarshalling behaviour.
When unmarshalling a
UnmarshalExceptionwill result in aWebApplicationExceptionbeing thrown with a status of 400 (Client error), and aJAXBExceptionwill result in aWebApplicationExceptionbeing thrown with a status of 500 (Internal Server error).When marshalling a
JAXBExceptionwill result in aWebApplicationExceptionbeing thrown with a status of 500 (Internal Server error).- Author:
- Paul Sandoz, Martin Matula
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractCollectionJaxbProvider.JaxbTypeCheckerThis is to allow customized JAXB collections checking.
-
Field Summary
-
Fields inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
UTF8
-
-
Constructor Summary
Constructors Constructor Description AbstractCollectionJaxbProvider(Providers ps)AbstractCollectionJaxbProvider(Providers ps, MediaType mt)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static ClassgetElementClass(Class<?> type, Type genericType)protected static StringgetElementName(Class<?> elementType)Get the element name for a given Java type.protected StringgetRootElementName(Class<?> elementType)Construct the name of the root element from it's Java type name.protected abstract XMLStreamReadergetXMLStreamReader(Class<?> elementType, MediaType mediaType, jakarta.xml.bind.Unmarshaller unmarshaller, InputStream entityStream)Get theXMLStreamReaderfor unmarshalling.booleanisReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)booleanisWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)ObjectreadFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String,String> httpHeaders, InputStream inputStream)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)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, MediaType mediaType, Charset c, jakarta.xml.bind.Marshaller m, OutputStream entityStream)Write a collection of JAXB objects as child elements of the root element.voidwriteTo(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
-
-
-
-
Method Detail
-
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
public static boolean verifyCollectionSubclass(Class<?> type)
-
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 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.
-
getRootElementName
protected final String getRootElementName(Class<?> elementType)
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
protected static String getElementName(Class<?> elementType)
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.
-
-