![]() ![]() If you get an error stating "Service ClassMappingTypeService not found", you are probably using KMongo in an environment where your application is loaded at runtime (e.g. Explicitly defining the ClassMappingTypeService ¶ Kotlin experts will prefer kotlinx serialization, as it should provide the best performance. We expect that, for most of the projects, the "native" bindings will be perfectly OK.įor complex projects, or if you have already Jackson skills, the Jackson object mapping is a really nice choice. Using the changeIdController function to avoid completely reflection. Avoid completely reflection ¶īy default, there is still a little bit of reflection involved when persisting a document, in order to retrieve dynamically (for example polymorphic) kotlinx Module or Serializer. Use registerModule or registerSerializer functions in order to register new ![]() The main advantage of this kind of mapping is that almost no (slow) reflection is involved. Starting with 3.11.2 version, KMongo also supports Kotlinx Serialization mapping. For example, top level POJO cannot contain any type parameters. No other dependency than the core java mongo driver is required.Īll the common cases are covered. KMongo uses it to provide object mapping for Kotlin. Started in 3.5.0 (July 2017), the java driver introduces a new POJO mapping framework. However, if you don't use already Jackson, you add a new quite complex library to your dependencies. If you need custom serialization or deserialization, you will not be blocked, you can implement it.Īlso, if you already use Jackson for json serialization (for rest services for example), the library is already in your list of dependencies. With the Jackson library, you get full support of one of the most powerful data-binding java engine, in order to map your data objects. How to choose the mapping engine ¶ The Jackson choice ¶ You have also the option to use custom Jackson modules or custom rialization modules. Use ObjectMappingConfiguration.addCustomCodec function in order to register a custom codec. If you need to check equality, use a method like OffsetDateTime#withOffsetSameInstant on the loaded date. So, in this case, the loaded date will not usually be equals to the saved date - the Instant part of the date of course is the same. Whatever is the timezone of the saved date, you will get an UTC date when loading the date from Mongo. For Calendar, ZonedDateTime, OffsetDateTime and OffsetTime, KMongo provides built-in support for these "Date" classes:ĭates are always stored in Mongo in UTC. appl圜onnectionString ( ConnectionString ( connection )). ![]()
0 Comments
Leave a Reply. |