EJson
Main entry point to work with EJSON serialization. EJSON is a JSON format that can be used to encode all BSON datatypes.
A default instance is provided via EJson.Default, but if you require an instance with certain registered serializers or different options you can instantiate it with EJson.
This string format also supports encoding to or from a BsonValue with the functions decodeFromBsonValue and encodeToBsonValue.
Example of usage:
@Serializable
class DataHolder(val id: Int, val data: String, val bsonValue: BsonValue)
val ejson = EJson
val instance = DataHolder(42, "some data", BsonObjectId() }
// Plain StringFormat usage
val stringOutput: String = ejson.encodeToString(instance)
// BsonValue serialization
val bsonValue: BsonValue = ejson.encodeToBsonValue(instance)
// Deserialize from string
val deserialized: DataHolder = ejson.decodeFromString<DataHolder>(stringOutput)
// Deserialize from BsonValue
val deserializedFromBsonValue: DataHolder = ejson.decodeFromBsonValue<DataHolder>(bsonValue)
// Deserialize from string to BsonValue
val deserializedToBsonValue: BsonValue = Bson(stringOutput)It does not support polymorphic serializers yet.
Types
Functions
Deserializes the given value into a value of type T using the given deserializer.
Deserializes the given EJSON string into a value of type T using the given deserializer.
Serializes the given value into an equivalent BsonValue using the given serializer
Serializes the value into an equivalent EJSON using the given serializer.