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

public Class Jaxb2XmlEncoder

extends AbstractSingleValueEncoder<Object>
Class Inheritance
Imports
java.io.OutputStream, java.nio.charset.StandardCharsets, java.util.Map, java.util.function.Function, jakarta.xml.bind.JAXBElement, .JAXBException, .MarshalException, .Marshaller, jakarta.xml.bind.annotation.XmlRootElement, .XmlType, reactor.core.publisher.Flux, .Mono, org.springframework.core.ResolvableType, org.springframework.core.codec.AbstractSingleValueEncoder, .CodecException, .EncodingException, .Hints, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DataBufferUtils, org.springframework.core.log.LogFormatUtils, org.springframework.http.MediaType, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .MimeType, .MimeTypeUtils

Encode from single value to a byte stream containing XML elements.

@XmlElements and @XmlElement can be used to specify how collections should be marshalled.

Authors
Sebastien Deleuze, Arjen Poutsma
Since
5.0
See Also
Jaxb2XmlDecoder

Field Summary

Modifier and TypeField and Description
private final JaxbContextContainer
private Function<Marshaller, Marshaller>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
canEncode(ResolvableType
the type of elements in the source stream
elementType
,
MimeType
the MIME type for the output stream (can be null if not specified)
mimeType
)

Overrides org.springframework.core.codec.AbstractEncoder.canEncode.

Implements org.springframework.core.codec.Encoder.canEncode.

Whether the encoder supports the given source element type and the MIME type for the output stream.

protected Flux<DataBuffer>
encode(Object
the value to process
value
,
DataBufferFactory
a buffer factory used to create the output
bufferFactory
,
ResolvableType
the stream element type to process
valueType
,
MimeType
the mime type to process
mimeType
,
Map<String, Object>
additional information about how to do decode, optional
hints
)

Implements abstract org.springframework.core.codec.AbstractSingleValueEncoder.encode.

Encode T to an output DataBuffer stream.

public DataBuffer
encodeValue(Object
the value to be encoded
value
,
DataBufferFactory
for creating the output DataBuffer
bufferFactory
,
ResolvableType
the type for the value being encoded
valueType
,
MimeType
the MIME type for the output content (optional)
mimeType
,
Map<String, Object>
additional information about how to encode
hints
)

Overrides default org.springframework.core.codec.Encoder.encodeValue.

Encode an Object of type T to a data buffer.

public Function<Marshaller, Marshaller>
getMarshallerProcessor()

Return the configured processor for customizing Marshaller instances.

private static Class<?>
private Marshaller
public void
setMarshallerProcessor(Function<Marshaller, Marshaller>
the function to use
processor
)

Configure a processor function to customize Marshaller instances.

Inherited from org.springframework.core.codec.AbstractSingleValueEncoder:
encode

Field Detail

jaxbContextsback to summary
private final JaxbContextContainer jaxbContexts
marshallerProcessorback to summary
private Function<Marshaller, Marshaller> marshallerProcessor

Constructor Detail

Jaxb2XmlEncoderback to summary
public Jaxb2XmlEncoder()

Method Detail

canEncodeback to summary
public boolean canEncode(ResolvableType elementType, MimeType mimeType)

Overrides org.springframework.core.codec.AbstractEncoder.canEncode.

Implements org.springframework.core.codec.Encoder.canEncode.

Doc from org.springframework.core.codec.Encoder.canEncode.

Whether the encoder supports the given source element type and the MIME type for the output stream.

Parameters
elementType:ResolvableType

the type of elements in the source stream

mimeType:MimeType

the MIME type for the output stream (can be null if not specified)

Returns:boolean

true if supported, false otherwise

Annotations
@Override
encodeback to summary
protected Flux<DataBuffer> encode(Object value, DataBufferFactory bufferFactory, ResolvableType valueType, MimeType mimeType, Map<String, Object> hints)

Implements abstract org.springframework.core.codec.AbstractSingleValueEncoder.encode.

Doc from org.springframework.core.codec.AbstractSingleValueEncoder.encode.

Encode T to an output DataBuffer stream.

Parameters
value:Object

the value to process

bufferFactory:DataBufferFactory

a buffer factory used to create the output

valueType:ResolvableType

the stream element type to process

mimeType:MimeType

the mime type to process

hints:Map<String, Object>

additional information about how to do decode, optional

Returns:Flux<DataBuffer>

the output stream

Annotations
@Override
encodeValueback to summary
public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, ResolvableType valueType, MimeType mimeType, Map<String, Object> hints)

Overrides default org.springframework.core.codec.Encoder.encodeValue.

Doc from org.springframework.core.codec.Encoder.encodeValue.

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

By default this method raises UnsupportedOperationException and it is expected that some encoders cannot produce a single buffer or cannot do so synchronously (e.g. encoding a Resource).

Parameters
value:Object

the value to be encoded

bufferFactory:DataBufferFactory

for creating the output DataBuffer

valueType:ResolvableType

the type for the value being encoded

mimeType:MimeType

the MIME type for the output content (optional)

hints:Map<String, Object>

additional information about how to encode

Returns:DataBuffer

the encoded content

Annotations
@Override
getMarshallerProcessorback to summary
public Function<Marshaller, Marshaller> getMarshallerProcessor()

Return the configured processor for customizing Marshaller instances.

Since
5.1.3
getMarshallerTypeback to summary
private static Class<?> getMarshallerType(Object value)
initMarshallerback to summary
private Marshaller initMarshaller(Class<?> clazz) throws CodecException, JAXBException
setMarshallerProcessorback to summary
public void setMarshallerProcessor(Function<Marshaller, Marshaller> processor)

Configure a processor function to customize Marshaller instances.

Parameters
processor:Function<Marshaller, Marshaller>

the function to use

Since
5.1.3