Skip to content

Add support to encode Json in BsonEncoder #21

Description

@ageorgousakis

Some times it is required to serialise in Bson a property that is mapped to a Map<String, Any?> type. It would be nice if the Map<String, Any?> can be encoded to a Json structure. This can be easily done by adding one method in BsonReader to encode a JSON string

fun encodeJson(value: String) {
        when (state) {
            STATE.VALUE -> writer.pipe(JsonReader(value))
            STATE.NAME -> throw SerializationException("Json is not supported as a key of map")
        }
}

I created a patch that add this method. There is also a test case KBsonMapAnyTest.kt that you can check and understand better why this method is needed.

add_support_to_encode_Json_structure.txt

It will be also nice if there was a decoder from BsonDocument to Map<String, Any?>. I tried to use BsonFlexibleDecoder but maybe there is a better way to do it. You can check parseBsonDocument inside MapAnySerializer object in the test classes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions