org.springframework.http.codec.xml

## Class Jaxb2XmlEncoder

- java.lang.Object
- - org.springframework.core.codec.AbstractEncoder<T>
  - - org.springframework.core.codec.AbstractSingleValueEncoder<Object>
    - - org.springframework.http.codec.xml.Jaxb2XmlEncoder

- All Implemented Interfaces:
    Encoder<Object>

      public class Jaxb2XmlEncoder
      extends AbstractSingleValueEncoder<Object>

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

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

  Since:
    5.0
  Author:
    Sebastien Deleuze, Arjen Poutsma
  See Also:
    `Jaxb2XmlDecoder`

- - ### Field Summary

    - ### Fields inherited from class org.springframework.core.codec.AbstractEncoder

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Jaxb2XmlEncoder()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canEncode(ResolvableType elementType, MimeType mimeType)` Whether the encoder supports the given source element type and the MIME type for the output stream.
    `protected reactor.core.publisher.Flux<DataBuffer>` | `encode(Object value, DataBufferFactory bufferFactory, ResolvableType valueType, MimeType mimeType, Map<String,Object> hints)` Encode `T` to an output `DataBuffer` stream.
    `DataBuffer` | `encodeValue(Object value, DataBufferFactory bufferFactory, ResolvableType valueType, MimeType mimeType, Map<String,Object> hints)` Encode an Object of type T to a data buffer.
    `Function<Marshaller,Marshaller>` | `getMarshallerProcessor()` Return the configured processor for customizing Marshaller instances.
    `void` | `setMarshallerProcessor(Function<Marshaller,Marshaller> processor)` Configure a processor function to customize Marshaller instances.

    - ### Methods inherited from class org.springframework.core.codec.AbstractSingleValueEncoder

      `encode`

    - ### Methods inherited from class org.springframework.core.codec.AbstractEncoder

      `getEncodableMimeTypes, getLogger, setLogger`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.springframework.core.codec.Encoder

      `getEncodableMimeTypes`

- - ### Constructor Detail

    - #### Jaxb2XmlEncoder

          public Jaxb2XmlEncoder()

  - ### Method Detail

    - #### setMarshallerProcessor

          public void setMarshallerProcessor(Function<Marshaller,Marshaller> processor)

      Configure a processor function to customize Marshaller instances.
      Parameters:
        `processor` - the function to use
      Since:
        5.1.3

    - #### getMarshallerProcessor

          public Function<Marshaller,Marshaller> getMarshallerProcessor()

      Return the configured processor for customizing Marshaller instances.
      Since:
        5.1.3

    - #### canEncode

          public boolean canEncode(ResolvableType elementType,
                                   @Nullable
                                   MimeType mimeType)

      Description copied from interface: `Encoder`
      Whether the encoder supports the given source element type and the MIME type for the output stream.
      Specified by:
        `canEncode` in interface `Encoder<Object>`
      Overrides:
        `canEncode` in class `AbstractEncoder<Object>`
      Parameters:
        `elementType` - the type of elements in the source stream
        `mimeType` - the MIME type for the output stream (can be `null` if not specified)
      Returns:
        `true` if supported, `false` otherwise

    - #### encode

          protected reactor.core.publisher.Flux<DataBuffer> encode(Object value,
                                                                   DataBufferFactory bufferFactory,
                                                                   ResolvableType valueType,
                                                                   @Nullable
                                                                   MimeType mimeType,
                                                                   @Nullable
                                                                   Map<String,Object> hints)

      Description copied from class: `AbstractSingleValueEncoder`
      Encode `T` to an output `DataBuffer` stream.
      Specified by:
        `encode` in class `AbstractSingleValueEncoder<Object>`
      Parameters:
        `value` - the value to process
        `bufferFactory` - a buffer factory used to create the output
        `valueType` - the stream element type to process
        `mimeType` - the mime type to process
        `hints` - additional information about how to do decode, optional
      Returns:
        the output stream

    - #### encodeValue

          public DataBuffer encodeValue(Object value,
                                        DataBufferFactory bufferFactory,
                                        ResolvableType valueType,
                                        @Nullable
                                        MimeType mimeType,
                                        @Nullable
                                        Map<String,Object> hints)

      Description copied from interface: `Encoder`
      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` - the value to be encoded
        `bufferFactory` - for creating the output `DataBuffer`
        `valueType` - the type for the value being encoded
        `mimeType` - the MIME type for the output content (optional)
        `hints` - additional information about how to encode
      Returns:
        the encoded content