Class ServletWebSocketMessageEncoder

java.lang.Object
io.micronaut.servlet.websocket.ServletWebSocketMessageEncoder

@Internal @Singleton public final class ServletWebSocketMessageEncoder extends Object
Encodes an outbound WebSocket message the way the Netty server does: byte-like payloads become binary frames, CharSequence and java.lang types become text frames, and anything else is written through the MessageBodyHandlerRegistry as a text frame using the configured media type, JSON by default.
Since:
6.2.0
Author:
graemerocher
  • Constructor Details

    • ServletWebSocketMessageEncoder

      public ServletWebSocketMessageEncoder(io.micronaut.http.body.MessageBodyHandlerRegistry messageBodyHandlerRegistry, io.micronaut.core.convert.ConversionService conversionService)
      Default constructor.
      Parameters:
      messageBodyHandlerRegistry - The message body handler registry
      conversionService - The conversion service
  • Method Details

    • encode

      public EncodedMessage encode(Object message, io.micronaut.http.MediaType mediaType)
      Encodes the given message.
      Parameters:
      message - The message, never null
      mediaType - The media type to use when the message needs a body writer
      Returns:
      The encoded message
      Throws:
      io.micronaut.websocket.exceptions.WebSocketSessionException - if the message cannot be encoded