Interface KeysAwareEncoder

All Superinterfaces:
AutoCloseable, Encoder
All Known Implementing Classes:
BsonWriterEncoder, JacksonEncoder, ProtobufEncoder, XmlStaxEncoder

@Internal public interface KeysAwareEncoder extends Encoder
Optional encoder capability for writing object keys from a known key set.
Since:
3.1
Author:
Denis Stepanov
  • Method Details

    • of

      static KeysAwareEncoder of(Encoder encoder)
      Adapt the encoder to the keys-aware contract.
      Parameters:
      encoder - The encoder
      Returns:
      A keys-aware encoder
    • encodeKey

      void encodeKey(Keys keys, int index) throws IOException
      Encode a key by index from the supplied key set.
      Parameters:
      keys - The keys
      index - The key index
      Throws:
      IOException - If an unrecoverable error occurs
    • encodeStringValue

      default void encodeStringValue(Keys values, int index) throws IOException
      Encode a string value by index from the supplied set of constant values, such as the serialized names of the constants of an enum. An encoder can write a value it prepared once for the set instead of encoding the string again.
      Parameters:
      values - The values
      index - The value index
      Throws:
      IOException - If an unrecoverable error occurs
      Since:
      3.3
    • encodeStringValue

      static void encodeStringValue(Encoder encoder, Keys values, int index) throws IOException
      Encode a string value by index from the supplied set of constant values with any encoder.
      Parameters:
      encoder - The encoder
      values - The values
      index - The value index
      Throws:
      IOException - If an unrecoverable error occurs
      Since:
      3.3