-
Notifications
You must be signed in to change notification settings - Fork 604
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
Record objects failing silently with Jakarta EE 9.1 #19698
Comments
Hi @rdean, thank's for bringing this to our attention. I am out of the office today, but I'll investigate on Monday. |
Hi @rdean I think I have this reproduced, or close. What is the HTTP status code of your curl command? When I try to hit my endpoint I'm getting a My hunch is that our JAX-RS implementation (Resteasy 4.7.2.Final) doesn't yet support record types. At first I thought that the issue was probably that we don't ship a MessageBodyWriter that supports record types. But, with no errors in the logs and getting a 404, I think the error is even earlier than message serialization. Rather, Resteasy isn't finding the endpoint at all. Here is the basic application I'm using to reproduce with Java 17 temurin
I'm deploying the application via the |
I got a
|
I added my example to a personal repo on GitHub: https://github.com/rdean/jee-example |
Thanks! |
@rdean I was able to reproduce the issue with your provided sample, thank you! When I enabled Liberty trace I found what I expected:
What this means is that Liberty is selecting our built in I did some searching and found this blog post: Basically, JSONB doesn't currently support record types. But that article is from 2019 and references Johnzon, we use Yasson as our JSONB implementation in Open Liberty. So I found this article: It's a little bit newer, but references Yasson. Ultimately it says the same thing. Records will likely be supported in future versions of JSONB. Where does that leave us now? Currently, to serialize record types you'll have to provide your own MessageBodyWriter that supports serialization of java record types to json. It looks like Jackson 2.12.3 can do this: |
Here's a blog on how to bring your own Jackson with your application: https://openliberty.io/blog/2020/11/11/byo-jackson.html |
Now that Java 17 support is officially claimed, I think it is important to get this fixed (or at least to more visibly communicate about this exception). |
I took a look and we currently depend on Yasson 2.0.1 for EE9 and 3.0.0. for EE10. Record support was added to Yasson 2.0.3. So, this works with EE10, but we need to update EE9 to 2.0.3. |
Hi @WhiteCat22! 2.0.3 does not support : final JsonbConfig jsonbConfig =
new JsonbConfig()
.withPropertyVisibilityStrategy(new PrivateVisibilityStrategy())
.withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_UNDERSCORES); When using Jsonb, it will still try to look for a property "firstName" instead of "first_name". |
We upgraded to 2.0.4. Does that resolve the issue? |
Nope, 2.0.4 still has the wrong behaviour. Just updated my new IT: Jsonb is instantiated here: https://github.com/bmarwell/jaxrs-test-showcase/blob/70b783a1853c7c35fcf21ac56ebcd64d505cc174/app/web/rest-impl/src/main/java/io/github/jaxrstesting/web/rest/impl/data/DataInitializer.java Works fine in the unit test: Fails in the Open Liberty IT. Fails in my unit test when I downgrade from 3.0.2 to 2.0.4. To execute the test, use Workaround: use the jsonbContainer + bells-Feature (untested): <server>
<featureManager>
<feature>jsonbContainer-1.0</feature>
</featureManager>
<bell libraryRef="johnzon"/>
<library id="johnzon">
<fileset dir="${server.config.dir}/johnzon"includes="*.jar"/>
</library>
</server> |
I dug into this a little further. Neither yasson 3 can be used (different API, would need jsonbContainer-3.0), nor johnzon (Uses classifiers, which is not supported by Liberty). However, adding some null checks revealed that this is in fact a problem in Yasson. Yasson seems to ignore the PropertyNamingStrategy in any version of 2.x / 3.x. Will open a bug over there. // edit: eclipse-ee4j/yasson#583 |
... here's the PR |
I'm experimenting with Java 17 and JakartaEE 9.1 restful services and running into issues with
Record
objects.I generated a project with a simple greeting service that returns a
Record
type:where
GreetingResponse
isWhen accessing the resource
the response is
No error message is produced in the logs.
Yasson was recently updated to support
Record
types. I flirted with the jsonbContainer-2.0 feature but the documentation is unclear on how to configure in server.xml or where to put the jar / whether or not a<bell>
is required.The text was updated successfully, but these errors were encountered: