Top Description Fields Constructors Methods
org.springframework.http.codec.xml

public Class Jaxb2XmlDecoder

extends AbstractDecoder<Object>
Class Inheritance
Imports
java.nio.charset.Charset, java.util.ArrayList, .Iterator, .List, .Map, .Set, java.util.function.Function, javax.xml.namespace.QName, javax.xml.stream.XMLEventReader, .XMLInputFactory, .XMLStreamException, javax.xml.stream.events.XMLEvent, jakarta.xml.bind.JAXBElement, .JAXBException, .UnmarshalException, .Unmarshaller, jakarta.xml.bind.annotation.XmlRootElement, .XmlSeeAlso, .XmlType, org.reactivestreams.Publisher, reactor.core.Exceptions, reactor.core.publisher.Flux, .Mono, org.springframework.core.ResolvableType, org.springframework.core.codec.AbstractDecoder, .CodecException, .DecodingException, .Hints, org.springframework.core.io.buffer.DataBuffer, .DataBufferLimitException, .DataBufferUtils, org.springframework.core.log.LogFormatUtils, org.springframework.http.MediaType, org.springframework.lang.NonNull, .Nullable, org.springframework.util.MimeType, .MimeTypeUtils, org.springframework.util.xml.StaxUtils

Decode from a bytes stream containing XML elements to a stream of Objects (POJOs).
Authors
Sebastien Deleuze, Arjen Poutsma
Since
5.0
See Also
Jaxb2XmlEncoder

Field Summary

Modifier and TypeField and Description
private static final XMLInputFactory
private final JaxbContextContainer
private int
private Function<Unmarshaller, Unmarshaller>
private final XmlEventDecoder
Inherited from org.springframework.core.codec.AbstractDecoder:
logger

Constructor Summary

AccessConstructor and Description
public
public
Jaxb2XmlDecoder(MimeType...
supported MIME types
supportedMimeTypes
)

Create a Jaxb2XmlDecoder with the specified MIME types.

Method Summary

Modifier and TypeMethod and Description
public boolean
canDecode(ResolvableType
the target element type for the output stream
elementType
,
MimeType
the mime type associated with the stream to decode (can be null if not specified)
mimeType
)

Overrides org.springframework.core.codec.AbstractDecoder.canDecode.

Implements org.springframework.core.codec.Decoder.canDecode.

Whether the decoder supports the given target element type and the MIME type of the source stream.

public Flux<Object>
decode(Publisher<DataBuffer>
the DataBuffer input stream to decode
inputStream
,
ResolvableType
the expected type of elements in the output stream; this type must have been previously passed to the canDecode method and it must have returned true.
elementType
,
MimeType
the MIME type associated with the input stream (optional)
mimeType
,
Map<String, Object>
additional information about how to do decode
hints
)

Implements org.springframework.core.codec.Decoder.decode.

Decode a DataBuffer input stream into a Flux of T.

public Object
decode(DataBuffer
the DataBuffer to decode
dataBuffer
,
ResolvableType
the expected output type
targetType
,
MimeType
the MIME type associated with the data
mimeType
,
Map<String, Object>
additional information about how to do decode
hints
)

Overrides default org.springframework.core.codec.Decoder.decode.

Decode a data buffer to an Object of type T.

public Mono<Object>
decodeToMono(Publisher<DataBuffer>
the DataBuffer input stream to decode
input
,
ResolvableType
the expected type of elements in the output stream; this type must have been previously passed to the canDecode method and it must have returned true.
elementType
,
MimeType
the MIME type associated with the input stream (optional)
mimeType
,
Map<String, Object>
additional information about how to do decode
hints
)

Overrides org.springframework.core.codec.AbstractDecoder.decodeToMono.

Implements org.springframework.core.codec.Decoder.decodeToMono.

Decode a DataBuffer input stream into a Mono of T.

private static String
encoding(MimeType mimeType)

public int
getMaxInMemorySize()

Return the configured byte count limit.

public Function<Unmarshaller, Unmarshaller>
getUnmarshallerProcessor()

Return the configured processor for customizing Unmarshaller instances.

private Unmarshaller
initUnmarshaller(Class<?> outputClass)

public void
setMaxInMemorySize(int
the max number of bytes to buffer, or -1 for unlimited
byteCount
)

Set the max number of bytes that can be buffered by this decoder.

public void
setUnmarshallerProcessor(Function<Unmarshaller, Unmarshaller>
the function to use
processor
)

Configure a processor function to customize Unmarshaller instances.

private Object
unmarshal(List<XMLEvent> events, Class<?> outputClass)

Inherited from org.springframework.core.codec.AbstractDecoder:
getDecodableMimeTypesgetLoggersetLogger

Field Detail

inputFactoryback to summary
private static final XMLInputFactory inputFactory
jaxbContextsback to summary
private final JaxbContextContainer jaxbContexts
maxInMemorySizeback to summary
private int maxInMemorySize
unmarshallerProcessorback to summary
private Function<Unmarshaller, Unmarshaller> unmarshallerProcessor
xmlEventDecoderback to summary
private final XmlEventDecoder xmlEventDecoder

Constructor Detail

Jaxb2XmlDecoderback to summary
public Jaxb2XmlDecoder()
Jaxb2XmlDecoderback to summary
public Jaxb2XmlDecoder(MimeType... supportedMimeTypes)

Create a Jaxb2XmlDecoder with the specified MIME types.

Parameters
supportedMimeTypes:MimeType[]

supported MIME types

Since
5.1.9

Method Detail

canDecodeback to summary
public boolean canDecode(ResolvableType elementType, MimeType mimeType)

Overrides org.springframework.core.codec.AbstractDecoder.canDecode.

Implements org.springframework.core.codec.Decoder.canDecode.

Doc from org.springframework.core.codec.Decoder.canDecode.

Whether the decoder supports the given target element type and the MIME type of the source stream.

Parameters
elementType:ResolvableType

the target element type for the output stream

mimeType:MimeType

the mime type associated with the stream to decode (can be null if not specified)

Returns:boolean

true if supported, false otherwise

Annotations
@Override
decodeback to summary
public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints)

Implements org.springframework.core.codec.Decoder.decode.

Doc from org.springframework.core.codec.Decoder.decode.

Decode a DataBuffer input stream into a Flux of T.

Parameters
inputStream:Publisher<DataBuffer>

the DataBuffer input stream to decode

elementType:ResolvableType

the expected type of elements in the output stream; this type must have been previously passed to the canDecode method and it must have returned true.

mimeType:MimeType

the MIME type associated with the input stream (optional)

hints:Map<String, Object>

additional information about how to do decode

Returns:Flux<Object>

the output stream with decoded elements

Annotations
@Override
decodeback to summary
public Object decode(DataBuffer dataBuffer, ResolvableType targetType, MimeType mimeType, Map<String, Object> hints) throws DecodingException

Overrides default org.springframework.core.codec.Decoder.decode.

Doc from org.springframework.core.codec.Decoder.decode.

Decode a data buffer to an Object of type T. This is useful for scenarios, that distinct messages (or events) are decoded and handled individually, in fully aggregated form.

Parameters
dataBuffer:DataBuffer

the DataBuffer to decode

targetType:ResolvableType

the expected output type

mimeType:MimeType

the MIME type associated with the data

hints:Map<String, Object>

additional information about how to do decode

Returns:Object

the decoded value, possibly null

Annotations
@Override
@NonNull
decodeToMonoback to summary
public Mono<Object> decodeToMono(Publisher<DataBuffer> input, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints)

Overrides org.springframework.core.codec.AbstractDecoder.decodeToMono.

Implements org.springframework.core.codec.Decoder.decodeToMono.

Doc from org.springframework.core.codec.Decoder.decodeToMono.

Decode a DataBuffer input stream into a Mono of T.

Parameters
input:Publisher<DataBuffer>

the DataBuffer input stream to decode

elementType:ResolvableType

the expected type of elements in the output stream; this type must have been previously passed to the canDecode method and it must have returned true.

mimeType:MimeType

the MIME type associated with the input stream (optional)

hints:Map<String, Object>

additional information about how to do decode

Returns:Mono<Object>

the output stream with the decoded element

Annotations
@Override
encodingback to summary
private static String encoding(MimeType mimeType)
Annotations
@Nullable
getMaxInMemorySizeback to summary
public int getMaxInMemorySize()

Return the configured byte count limit.

Since
5.1.11
getUnmarshallerProcessorback to summary
public Function<Unmarshaller, Unmarshaller> getUnmarshallerProcessor()

Return the configured processor for customizing Unmarshaller instances.

Since
5.1.3
initUnmarshallerback to summary
private Unmarshaller initUnmarshaller(Class<?> outputClass) throws CodecException, JAXBException
setMaxInMemorySizeback to summary
public void setMaxInMemorySize(int byteCount)

Set the max number of bytes that can be buffered by this decoder. This is either the size of the entire input when decoding as a whole, or when using async parsing with Aalto XML, it is the size of one top-level XML tree. When the limit is exceeded, DataBufferLimitException is raised.

By default this is set to 256K.

Parameters
byteCount:int

the max number of bytes to buffer, or -1 for unlimited

Since
5.1.11
setUnmarshallerProcessorback to summary
public void setUnmarshallerProcessor(Function<Unmarshaller, Unmarshaller> processor)

Configure a processor function to customize Unmarshaller instances.

Parameters
processor:Function<Unmarshaller, Unmarshaller>

the function to use

Since
5.1.3
unmarshalback to summary
private Object unmarshal(List<XMLEvent> events, Class<?> outputClass)