Replies: 5 comments 1 reply
-
You'd provide a |
Beta Was this translation helpful? Give feedback.
-
Thanks, I did figure this out. As I've noted previously, a @CodecProvider annotation would be nicer. Everything else works via annotation, and if you can find and use all of those, registering a class annotated with @CodecProvider (Class<?> for which conversion is provided) seems nicer. And as long as we're on that, the actual codecs are kind of a pain. Working directly with BsonReader and BsonWriter means figuring out how reading/writing types, names and values works. Not rocket science, but still awkward. Would be nicer to take maybe a BsonValue and return an instance of type, and take such an instance and return a BsonValue to be written to the db. I think in part not having a canonical json representation with a nice interface is what's missing. Jackson used to suffer from the same problem before institutionalizing JsonNode as its canonical representation. |
Beta Was this translation helpful? Give feedback.
-
In my opinion, the new Filter classes and filter() method were a positive change in the API. On the other had the loss of a fluent API for update operations was not so positive. I've ended up wrapping that back into a fluent API that tracks the requested updates in a list and emits an UpdateOperator[] on query execution. From my reading of the code, I think using BsonValue in set and update operations will work correctly and has the advantage of being well-defined. I'm not always positive how a Java Object will be interpreted, but using a BsonValue I know exactly what I'm getting. It would seem a natural custom conversion point to take an arbitrary Java type and output BsonValue, and visa versa. |
Beta Was this translation helpful? Give feedback.
-
Agreed about the fluent API. But it had its own (implemenation) wrinkles that kept getting in the way (especially in the Query API). This approach is a much simpler implementation and is actually user extensible since anyone can create a new If I were to add an API to paper over the |
Beta Was this translation helpful? Give feedback.
-
Good points on BsonValues. You could always adopt JsonNode from Jackson, but I see where you would want independence. But a JsonNode-like series of classes that knows how to convert itself to/from BsonValue would not be hard, and than you could accept codecs that translated to/from this canonical standard, and add an @codec or @CodecProvider to make the definition easy. I guess for 3.0, although that can all be done as pure extensions of the current APIs, so does not necessarily need a 3.0. UpdateOperators can be improved with a simple extension as well...
...or something similar. |
Beta Was this translation helpful? Give feedback.
-
I have a class that requires a custom codec. I used to 'register' these in 1.32. by creating a TypeConverter and using @converters(). I think now I should be creating a Codec, but what's the proper way to register such a codec in 2.3.0?
Beta Was this translation helpful? Give feedback.
All reactions