Skip to content
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

Conversation

fscarponi
Copy link

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

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.
@fscarponi fscarponi marked this pull request as draft May 15, 2024 16:25
lamba92 and others added 2 commits May 16, 2024 12:15
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)
@fscarponi fscarponi marked this pull request as ready for review May 16, 2024 10:19
@fscarponi fscarponi force-pushed the fabrizio.scarponi/revamp-encoding-decoding-with-KotlinXSerializationMapper branch from 7adad66 to 127b826 Compare May 16, 2024 15:35
private fun JsonObject.toDocument(): Document {
val document = Document.createDocument()
for ((key, value) in entries) {
document.put(key, value.toDocument(), true)
Copy link
Contributor

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.

Copy link
Author

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,
Copy link
Contributor

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.

Copy link
Author

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.
@anidotnet
Copy link
Contributor

Closing the PR for lack of activity. Feel free to reopen for further changes.

@anidotnet anidotnet closed this May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants