Zyle Moore
02/17/2025, 3:48 AMencodeSerializaleValue of the Encoder interface
> Encodes the value of type T by delegating the encoding process to the given serializer. For example, encodeInt call is equivalent to delegating integer encoding to Int.Companion.serializer: encodeSerializableValue(Int.serializer())
In the other Encoder examples I've seen, like JSON and Cbor and Protobuf, a different Encoder interface is created, which has different encode methods, like encodeTaggedInt or encodeJsonElement. Are these format-specific encode* methods just strongly-typed convenience methods, preferred over encodeSerializableValue? The documentation seems to indicate that even primitives could have an equivalent encodeSerializableValue call, instead of an interface-specific encodeInt method. Or at least, their effect on the Encoder should be the same.
The first part of the Encoder interface documentation says (my emphasis)
> Encoder is a core serialization primitive that encapsulates the knowledge of the underlying format and its storage, exposing only structural methods to the serializer, making it completely format-agnostic. Serialization process transforms a single value into the sequence of its primitive elements, also called its serial form, while encoding transforms these primitive elements into an actual format representation: JSON string, ProtoBuf ByteArray, in-memory map representation etc.
Is an encodeJsonElement really a primitive? Should it be treated as an entrypoint into another serialization (since it should be equivalent to something like encodeSerializableValue(JsonElement))? Is an Int as "structural" as a JsonElement?