Class ConvertingEncoderDecoderSupport<T,M>

java.lang.Object
org.springframework.web.socket.adapter.standard.ConvertingEncoderDecoderSupport<T,M>
Type Parameters:
T - the type being converted to (for Encoder) or from (for Decoder)
M - the WebSocket message type (String or ByteBuffer)
Direct Known Subclasses:
ConvertingEncoderDecoderSupport.BinaryDecoder, ConvertingEncoderDecoderSupport.BinaryEncoder, ConvertingEncoderDecoderSupport.TextDecoder, ConvertingEncoderDecoderSupport.TextEncoder

public abstract class ConvertingEncoderDecoderSupport<T,M> extends Object
Base class that can be used to implement a standard Encoder and/or Decoder. It provides encode and decode method implementations that delegate to a Spring ConversionService.

By default, this class looks up a ConversionService registered in the active ApplicationContext under the name 'webSocketConversionService'. This works fine for both client and server endpoints, in a Servlet container environment. If not running in a Servlet container, subclasses will need to override the getConversionService() method to provide an alternative lookup strategy.

Subclasses can extend this class and should also implement one or both of Encoder and Decoder. For convenience ConvertingEncoderDecoderSupport.BinaryEncoder, ConvertingEncoderDecoderSupport.BinaryDecoder, ConvertingEncoderDecoderSupport.TextEncoder and ConvertingEncoderDecoderSupport.TextDecoder subclasses are provided.

Since JSR-356 only allows Encoder/Decoder to be registered by type, instances of this class are therefore managed by the WebSocket runtime, and do not need to be registered as Spring Beans. They can, however, by injected with Spring-managed dependencies via @Autowire.

Converters to convert between the type and String or ByteBuffer should be registered.

Since:
4.0
Author:
Phillip Webb
See Also: