Package org.springframework.core.codec

# Class AbstractEncoder<T>

java.lang.Object
org.springframework.core.codec.AbstractEncoder<T>

Type Parameters:
  `T` - the element type

All Implemented Interfaces:
  `Encoder<T>`

Direct Known Subclasses:
  `AbstractSingleValueEncoder`, `ByteArrayEncoder`, `ByteBufferEncoder`, `CharSequenceEncoder`, `DataBufferEncoder`, `Netty5BufferEncoder`, `NettyByteBufEncoder`, `ResourceRegionEncoder`

public abstract class AbstractEncoder<T> extends Object implements Encoder<T>
Abstract base class for `Encoder` implementations.

Since:
  5.0
Author:
  Sebastien Deleuze, Arjen Poutsma

## Field Summary

Fields
Modifier and Type
Field
Description
`protected org.apache.commons.logging.Log`
`logger`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`AbstractEncoder(MimeType... supportedMimeTypes)`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`canEncode(ResolvableType elementType, MimeType mimeType)`
Whether the encoder supports the given source element type and the MIME type for the output stream.
`List<MimeType>`
`getEncodableMimeTypes()`
Return the list of MIME types supported by this Encoder.
`org.apache.commons.logging.Log`
`getLogger()`
Return the currently configured Logger.
`void`
`setLogger(org.apache.commons.logging.Log logger)`
Set an alternative logger to use than the one based on the class name.

### 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

`encode, encodeValue, getEncodableMimeTypes`

## Field Details

### logger

protected org.apache.commons.logging.Log logger

## Constructor Details

### AbstractEncoder

protected AbstractEncoder(MimeType... supportedMimeTypes)

## Method Details

### setLogger

public void setLogger(org.apache.commons.logging.Log logger)
Set an alternative logger to use than the one based on the class name.

Parameters:
  `logger` - the logger to use
Since:
  5.1

### getLogger

public org.apache.commons.logging.Log getLogger()
Return the currently configured Logger.

Since:
  5.1

### getEncodableMimeTypes

public List<MimeType> getEncodableMimeTypes()
Description copied from interface: `Encoder`
Return the list of MIME types supported by this Encoder. The list may not apply to every possible target element type and calls to this method should typically be guarded via `canEncode(elementType, null)`. The list may also exclude MIME types supported only for a specific element type. Alternatively, use `Encoder.getEncodableMimeTypes(ResolvableType)` for a more precise list.

Specified by:
  `getEncodableMimeTypes` in interface `Encoder<T>`
Returns:
  the list of supported MIME types

### 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<T>`
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