Package io.flutter.plugin.common

## Class JSONMessageCodec

- java.lang.Object
- - io.flutter.plugin.common.JSONMessageCodec

- All Implemented Interfaces:
    `MessageCodec<Object>`

      public final class JSONMessageCodec
      extends Object
      implements MessageCodec<Object>

  A `MessageCodec` using UTF-8 encoded JSON messages.

  This codec is guaranteed to be compatible with the corresponding JSONMessageCodec on the Dart side. These parts of the Flutter SDK are evolved synchronously.

  Supports the same Java values as `JSONObject.wrap(Object)`.

  On the Dart side, JSON messages are handled by the JSON facilities of the dart:convert package.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static JSONMessageCodec` | `INSTANCE` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Object` | `decodeMessage​(ByteBuffer message)` | Decodes the specified message from binary.
    `ByteBuffer` | `encodeMessage​(Object message)` | Encodes the specified message into binary.

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

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

- - ### Field Detail

    - #### INSTANCE

          public static final JSONMessageCodec INSTANCE

  - ### Method Detail

    - #### encodeMessage

          public ByteBuffer encodeMessage​(Object message)

      Description copied from interface: `MessageCodec`
      Encodes the specified message into binary.
      Specified by:
        `encodeMessage` in interface `MessageCodec<Object>`
      Parameters:
        `message` - the T message, possibly null.
      Returns:
        a ByteBuffer containing the encoding between position 0 and the current position, or null, if message is null.

    - #### decodeMessage

          public Object decodeMessage​(ByteBuffer message)

      Description copied from interface: `MessageCodec`
      Decodes the specified message from binary.

      Warning: The ByteBuffer is "direct" and it won't be valid beyond this call. Storing the ByteBuffer and using it later and will lead to a `java.nio.BufferUnderflowException`. If you want to retain the data you'll need to copy it.

      Specified by:
        `decodeMessage` in interface `MessageCodec<Object>`
      Parameters:
        `message` - the `ByteBuffer` message, possibly null.
      Returns:
        a T value representation of the bytes between the given buffer's current position and its limit, or null, if message is null.