-
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revamp encoding-decoding with KotlinXSerializationMapper #969
Revamp encoding-decoding with KotlinXSerializationMapper #969
Conversation
The serialization mapper now supports structured map keys. Also added a custom configuration option in DocumentFormat for users to specify their own parameters. Tests have been updated to reflect these changes.
The DocumentFormat has been refactored for better configuration, modularizing it and encapsulating related parameters in the newly introduced DocumentFormatConfiguration class. Also, DocumentFormatBuilder has been introduced to enable the creation of DocumentFormat instances with custom configuration. (cherry picked from commit b9e75c6)
…ith-KotlinXSerializationMapper
7adad66
to
127b826
Compare
private fun JsonObject.toDocument(): Document { | ||
val document = Document.createDocument() | ||
for ((key, value) in entries) { | ||
document.put(key, value.toDocument(), true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very much your use case specific change. If some other user choose to use this kotlinx.serialization they won't be able to use/query nested documents. Please see my comments here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use this comment to follow up the topic!
@@ -43,7 +45,7 @@ class KotlinXSerializationMapperTest { | |||
val someMap: Map<String, String>, | |||
val someSerializableObjectMap: Map<InnerObject, SomePolymorphType>, | |||
val innerObject: InnerObject, | |||
val id: String, | |||
@SerialName("_id") val id: String? = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend not to name any user defined field as "_id". It is reserved to store the NitriteId
in a document.
If you want to get hold of the NitriteId
, just use the datatype as NitriteId
and mark the field with @Id
annotation, any field name would be ok.
If not, keep the field name anything other than "_id" in the document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it!
…teID Added the 'allowDeepPut' setting to DocumentFormatBuilder and DocumentFormat classes, allowing for deeper control over the serialization process. Changed the name of the NitriteConfig's 'enableRepositoryValidation' field to 'validateRepositories' for better clarity. Also added serializer for NitriteId type to improve its handling during serialization process. Removed unused imports and adjusted tests accordingly.
Closing the PR for lack of activity. Feel free to reopen for further changes. |
The previous implementation of Document Encoding was missing Polymorphism support for maps and lists, on top of that there were many corner cases not handled.
Given the similarity between JSON and Documents, it makes sense to leverage on KotlinxJsonSerialization implementation and convert JsonObjects to Documents.
This allows having the same degree of freedom as JsonSerialization