-
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
Question: Is it forbidden to use adapted types as constructor parameters? #337
Comments
Hi @mkarg , did you try to enable CDI and make your adapter a bean ( |
Romain, thank you for picking this up. Good to hear that our code itself is correct, so apparently it is a bug of the implementation. This is what I needed to know. :-) Regarding your tipps: I gave it a try, but adding |
Yes, this can be a yasson issue since the lookup should work (cdi or not there). Reviewing more widely your sample I realize a part is maybe unclear in the spec.
Adapters are not intended to loop IIRC (for good reasons) so it should directly match some JSON compatible type and URI has its own adapter and is not a direct mapping (JsonValue, BigDecimal, BigInteger, int, long, double, String from memory). So something more like that should work:
|
I do not see that the spec is unclear. In fact, URI is JSON friendly (or with "friendly" you meant "JSON type" instead of "JSON-B type", because I read "friendly" as "explicitly handled by JSONB spec"?). The specification literally says: "convert the “unmappable” type (Original) into another one that JSONB can handle (Adapted)" in 4.7.1, and it says that URI MUST be handled by all implementations in 3.4.1. It might be the case that such a combination was not intended by the spec authors, but such a combination de-facto is not forbidden by the spec -- so how should the spec reader know? IMHO it would be pretty weird to limit adapters to map to numbers and Strings, while URI is explicitly mentioned in 3.4.1, so such an unwritten constraint would be rather unintuitive hence unexcpected by the reader (like: "You cannot put LEGO brick A ontop on LEGO brick B, even if they are contained in the same box and have compatible pins. Yes the construction manual didn't tell that, but everybody knows that."). Having said that, need to tell you that your example does not solve the problem: When adapting to String instead of URI, the result is the very same error message. Hence, I would say, I did nothing wrong, there is nothing unclear or missing in the spec, and it is simply a bug in Yasson. To open a bug report in Yasson, I just am waiting for the Yasson team to agree. @m0mus WDYT? |
@mkarg yes, I think we are in a blurry area of the spec so means it must be considered as unspecified by the reader. The clarification must decide if adapters are about JSON(-P) types or JSON(-B) types. Guess the intent was JSON-B but then it is also very weird from a design perspective because all not JSON-P types are handled by kind of adapters/(de)serializers by design since JSON-B is built on top of JSON-P and then you get to the loop issue of adapters which should clearly not be allowed so guess the sanest clarification from my window would be to stick to JSON-P at that level to be portable. That said your error is not yet at the type level but adapter resolution so guess your env misses something which ends in yasson area but still something to clarify at spec level but likely in another ticket. |
FYI: This bug is fixed since Yasson 3.0.0. Since that version, Yasson correctly uses @rmannibucau @m0mus Do we still need a spec change or is the existence of that fix a proof that the spec actually is meant in the sense of JSON-B-Types? |
@mkarg a fix is never a proof so tempted to say we are either on clarification or deprecation of adapters topic (indeed im still for their drop at the end after a few cycles). |
Dropping would mean breaking lots of existing apps. I doubt that the Jakarta EE WG would allow that. For the further discussion, do we need a new issue, or can we simply go on here? |
@mkarg once again you are the only one speaking of dropping anything for next release, Im more keen to deprecate and then plan a drop in one or two more releases as allowed by jakarta rules....even if they are not respected by several spec, Im one of the ones thinking stability is the key value of jakarta. Since adapter are not well defined nor their usage being as flexible as it looks, plus since it is superseeded easily by other api, i think it makes sense to aim at dropping them...but after deprecation etc... |
Fully understood and appreciated, but: Actually I am not speaking of the next release. The Jakarta EE WG does not allow to even just deprecate things. We did the same fault at JAX-RS, as we did not know that (we went down all that deprecation road and now we received the complaints that this is not allowed). Indeed, it was @struberg who told me recently that removal and even just deprecation apparently both are forbidden, even in new major releases. :-( |
Hmm, it always had been allowed at javaee and early jakarta times to deprecate things, with caution. Anyway nothing prevents the spec to say it is not well defined enough to be used which would be a bad deprecation but at least explicit to users to not use it when they care of bzing vendor locked or limited. |
Let's continue here: #341 |
I want to deserialize JSON into a POJO. The POJO is using
@JsonbConstructor
as it does not contain any setter methods. One of the parameters currently is of typeURI
. Everything deserializes fine. 😄For some reason, I want to map
URI
toX
. So I wrote aJsonbAdapter<X, URI>
and replaced the typeURI
in my POJO byX
. Unfortunately, the result now is:javax.json.bind.JsonbException: Internal error: WELD-001456: Argument resolvedBean must not be null
. 😢Is it forbidden to use adapted types as constructor parameters, or is this a bug of my runtime (here: Yasson)?
The text was updated successfully, but these errors were encountered: