-
Notifications
You must be signed in to change notification settings - Fork 73
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
jackson serializer and deserializer for UUID #155
Comments
I assume you use the default kmongo version - with jackson mapping. I suggest you register a new jackson Module with KMongoConfiguration#registerBsonModule method, that defines a custom UUID serializer and deserializer. HTH |
Thanks for your reply @zigzago Just to clarify by registering a custom serializer and deserializer, I will have to add a custom ser&deser for every class and their subclass that have the field uuid? Sorry if that doesn't sound right, I only started to use KMongo and the Jackson library yesterday
|
I just realized that I could just define a custom UUID serializer and deserializer and that solves the problem already. Would you consider adding such a module as the default behavior? The |
A PR would be welcome :) |
Sure, I will give it a try. I am thinking about extending the default jackson UUIDSerializer and UUIDDeserializer to support the mapping from both UUID subtype 0x03 and 0x04 and a configurable setting that allows user to choose in which format they would love to write to the db (with default set to 0x03 so it won't affect existing project). Does that sound right to you? By the way, I am not able to parse back the |
Question answered - but I'm not sure if it is a good idea to store an UUID as binary, and not as a string. Because querying a string is easier in mongo shell ;) |
yea, I get your concern, especially when sub-type 0x04 is not natively supported in several languages. But storing as UUID seems to be the right choice if scalability is concerned.
|
Hello, we are also interested in this fix (we also have to store UUID as subtype 0x04). Any updates on this issue ? Is there any progress ? |
@dpacierpnik
|
So in the latest version of the MongoDB client you can set the UUID type on Legacy, such that it is compatible. But we really want to use the new standard representation. I've already implemented a serializer and deserializer that work in my project. I'll go and see if I can create a PR for this project. I think that these settings should be part of the KMongoConfiguration, right? |
@marcdejonge @dpacierpnik
|
The MongoDb isn't the problem, the problem is the custom bson4jackson library that is translating custom objects (which can contain UUID's) to bson. This one actually doesn't support it. |
Maybe this pull requests also makes clear the changes I'd love to see. I do have a problem that I find it difficult to find the right place to configure these things. I'd love to rethink the way configuration is handle in KMongo, because it's not really extensible right now. Unless I'm overlooking some code, any hints on how to improve this? |
@marcdejonge Thank you for the PR Does KMongoConfiguration.registerBsonModule fill your needs? It allows to register any custom jackson module. Or do you need other kind of configuration? |
Sorry, I wasn't totally clear. Right now the KMongoConfiguration is an object (basically a singleton) that already loads the bsonMapper during init. The way I've solved it now is by being able to load a new bsonMapper with different configuration, but I would prefer it that this configuration is done during the configuration of the client. Even better would be some KMongoClientBuilder that makes it explicit that you can configure stuff first, and then create the client from that. I think something like that could be done in the future, but I think it would be a breaking change unfortunately. If you want I could make a proposal how this could look, but I would need a bit more information which configuration specific to KMongo now exists. Is it only this KMongoConfiguration object? |
I am interacting my kotlin program with a collection that has an
id
field of typeUUID(subtype4)
, instead of typeLUUID
(subtype3), which is represented asjava.util.UUID
in the Kotlin program.The problem is that when I retrieve the object back from the db, I get a
org.bson.types.Binary
Object. It makes sense but I want it to be a 'java.util.UUID` object in the program.Is it possible to overwrite the existing object mapper to support such transformation?
Thanks
The text was updated successfully, but these errors were encountered: