-
Notifications
You must be signed in to change notification settings - Fork 39
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
json-b tries to serialize jackson class #214
Comments
Maybe I got the issue wrong but sounds like you are missing a jaxrs routing provider (messagebody reader/writer delegating to jsonb or jackson depending the class). |
@rmannibucau Thanks for the hint. I guess, that is the reason. With jaxrs routing provider you mean something like The main application uses already |
This is the case (side note: this is 100% in jaxrs) but when a provider is too much gluton it breaks the delegation chain. For JSON mapping this is hard to make it right since all mappers should know each others to make the right choice so it - by construction - ends up in user land to switch between them and I think it is the "least worse" solution, a framework solution would likely be a disaster with all possibilities and combinations we see in applications these days. |
Unfortunatley, this is not the case for me. I guess, because: there are two jaxrs-providers (
I dont understand. Can you explain what "gluton" means?
And how can I switch between them within my application? How can I configure that |
(on the phone so just giving pointers) long story short all happens in MessageBodyReader (and similarly Writer which is generally the same class in practise). Both read/write sides have a test to know if the impl (jsonb or jackson) must handle the class. Both are gluton in the sense if it is json it handles the class - and ignores if it should be the other provider. If your app is not consistent on serialization side you must provide a custom impl handling the switch between both (dont expect jackson to know all json mapper nor jsonb to handle jackson). So just write a custom @Provider. Alternatively you can make jackson or your jsonb impl (it is not portable yet) able to read the other impl annotations depending the api used. To simplify the question the provider answer, it is equivalent to: being said the mimetype is json, should I handle class "Foo"? All providers will answer yes cause they actually handle all types (at least on write side) |
@rmannibucau Thanks for helping!
I tried it by adding this to my main application:
However, the result is still the same:
What does the word "gluton" mean? I also tried to solve this issue by adding explicitly only those classes which must be handled by the json-provider of my main application and ignores all other classes which are not listed:
However, this solution does also not work. The json-provider of my main application uses
How can I configure this in By far the best solution would be: The jaxrs routing provider of the main application should stop propagating the json processing provider to any 3rd-party lib. But I cannot find a solution for this. I tried it with custom |
Few things to add in your impl for it to be used:
|
Something like this:
does not work. And even if this work, it is not fine, because with this I will override the jackson-mapper from the 3rd party library and use my own with totally different configurations of what the author of the 3rd party lib wanted. No nice.
An implementation of Unfortunately, I cannot find a solution to keep
This is as I described not case. I does still not know what you mean with "too much gluton". I dont know what you mean with the word "gluton". |
No, MessageBodyReader, a generic one for all classes. It does not override 3rd party since you can inject the mapper from a ContextProvider in jaxrs. Also the else should use jsonb - looking up Jsonb from a context provider as well and creating it if null too. This is what we use in a few apps and used originally in geronimo microprofile openapi for example, it works well. Providers are just mapper selectors so you dont loose the config. Side note: should likely move back to quarkus since it is not a jsonb issue ;) |
Can you please give me a link with a working code? Anywhere in https://github.com/apache/geronimo-openapi? Or provide a generic implementation of
Yes, I thought it would be solvable by #88. However, I think it is a different use case. Unfortunately, quarkus treats this issue as invalid quarkusio/quarkus#5969. |
this must work in any JAX-RS container |
Thanks @rmannibucau I added this class to my application. The code makes sense and should normally differentiate between jsonb and jackson processing. However, it does not work in
As you see I also close this issue, because it is not a @rmannibucau Thanks for your time :) |
According to #88, we can adapt
json-b
annotation to 3rd party classes. Does this also mean that I do not have to use json-b annotations on classes to customize the json processing for each field/method because I can do this programmatically?Actually I have a big problem using
json-b
in quarkus. The problem is described in quarkusio/quarkus#5969. And maybe #88 would be a solution: My main app usesjson-b
-processing withjson-b
annotated classes. The problem is that I also use a 3rd party dependency which internally usesJackson
for json-processings. One one the 3rd party classes uses the following class to serialize with jackson:however, when this class is executed, unfortunately, json-b tries to serialize the class of the 3rd party dependency even though the 3rd party dependency should use its
jackson
for json processing. This results in an error forjson-b
becausejson-b
needs a no-arg-constructor which is missing:However, if
json-b
would ignore this class and delegate the json-processing of this class tojackson
(for what it was ment), then no error would occur, becausejackson
uses its@JsonCreator
. Actually, I cannot find a solution to make such a scenario working.So my question is: Can I disable the annotation processing or json processing with
json-b
for some classes with #88 programmatically? I dont know whyjson-b
tries to serialize this class because this class was ment forjackson
-processing and not forjson-b
-processing. Is there any config to use injson-b
which would solve this issue? Or is #88 the solution (e.g. programmatically disable thejson-b
-processing for some classes)?The text was updated successfully, but these errors were encountered: