bguerout/jongo

Unable to add my own ObjectIdUpdater without butchering JacksonMapper internals

Closed this issue · 6 comments

I am trying to write an ObjectIdUpdater that is capable of recognising javax.persistence.Id annotations as I don't want my generated code to depend on random implementation maven bundles.

Looking through the code I am wondering how one would register this ObjectIdUpdater with the JacksonMapper.Builder. this code will create a default updater and assign it to the objectIdUpdater field. During creation of the updater, it will supply the underlying ObjectMapper to the updater.

Now if I want to register a custom updater usign function withObjectIdUpdater line 86 I do not have access to this internal engine and cannot construct the updater.

Looks to me that either the org.jongo.marshall.jackson.JacksonMapper.Builder needs to set the context on the updater like it does for the default one or the JacksonMapper needs to pass this context to the updater in the constructor.

Does anyone have an example on how to write a custom ObjectIdUpdater and register this with the JacskonMapper properly?

I introduced that ObjectIdUpdater in b987df7 and I didn't provide a good way for custom implementations to use the JacksonEngine. It seems like the project would need a PR that:

  1. introduces some functional interfaces to JacksonMapper.Builder, so that the QueryFactory and ObjectIdUpdater can be constructed with the JacksonEngine.
  2. makes the Id annotation types used by JacksonObjectIdUpdater configurable, instead of the static binding it currently uses.

Looks like the main issue one would face is that the ObjectIdUpdater currently is constructed outside the builder and requires the JacksonEngine which has not yet been build.

I had to implement support for @javax.persistence.Id support in #318 and it was actually much simpler to update the existing JacksonObjectIdUpdater given I also had to modify the JongoAnnotationIntrospector. To support easier configurability the JacksonMapper.Builder would probably also have to be enhanced to set a custom AnnotationIntrospector in addition to the ObjectIdUpdater. Can't do one without the other.

Hello I can only browse code on my mobile phone for the moment.

Does this code helps you https://github.com/bguerout/jongo-extras/blob/master/json-query/src/test/java/org/jongo/json/JsonQueryCompatibilitySuiteTest.java ?
This code is from jongo-extras repository, a set of examples of how to extend jongo.

Let me know if it helps you to solve your problem.

I have added a new sample project in jongo-extras to show you how to configure Jongo to feet your need. This is still a work in progress and few hooks needs to be added in Jongo to ease custom annotation configuration.

For the moment

You can find how to configure Jongo here
https://github.com/bguerout/jongo-extras/blob/master/javax-persistence/src/test/java/org/jongo/persistence/PersistenceCompatibilitySuiteTest.java

Note that you can use the CompatibilitySuite to test your configuration against all unit/integration tests contained in Jongo project.

Since version 1.4.0, you can use JongoAnnotationIdSelector and JacksonObjectIdSelector see https://github.com/bguerout/jongo-extras/tree/master/javax-persistence for more informations

Released in 1.4.0

You can find more informations here: https://github.com/bguerout/jongo/releases