blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

Quarkus Resteasy JSONB fails to unmarshal entity view update interfaces

Open dubemarcantoine opened this issue 3 years ago • 3 comments

Description

I followed the following tutorial for Blaze Persistence with Quarkus: https://quarkus.io/guides/blaze-persistence

When I call the POST endpoint to create an entity, I get the following error:

javax.ws.rs.ProcessingException: RESTEASY008200: JSON Binding deserialization error: javax.json.bind.JsonbException:
Cannot infer a type for unmarshalling into: org.acme.GiftUpdateView

Expected behavior

I would expect my

Actual behavior

Steps to reproduce

I uploaded the following repository to demonstrate: https://github.com/dubemarcantoine/quarkus-blaze-help

To run: ./gradlew quarkusDev

Then do a POST request on this endpoint: localhost:8088/gifts with the following body:

{
    "name": "test"
}

Environment

Version: 1.6.7
JPA-Provider: Hibernate 5.6
DBMS: Postgresql 11 Application Server: Java 11 with Quarkus framework

Thanks for your help!

dubemarcantoine avatar Nov 03 '22 02:11 dubemarcantoine

Hi there. Thanks for such a detailed report and providing a sample app. I didn't yet look into it to deeply, but you seem to be missing the JAXRS-JSONB integration: https://persistence.blazebit.com/documentation/1.6/entity-view/manual/en_US/#jaxrs-setup

Can you try set that up and tell me if that makes it work for you?

beikov avatar Nov 03 '22 09:11 beikov

Hi @beikov , Thanks you very much for your quick response! This was indeed what I was missing.

Actually, by using the blaze-persistence-integration-jaxrs-jsonb package, I got this error:

2022-11-03 20:11:48,741 ERROR [io.qua.run.boo.StartupActionImpl] (Quarkus Main Thread) Error running Quarkus: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:103)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ExceptionInInitializerError
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at java.base/java.lang.Class.newInstance(Class.java:584)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:120)
        at io.quarkus.runner.GeneratedMain.main(Unknown Source)
        ... 6 more
Caused by: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.<clinit>(Unknown Source)
        ... 15 more
Caused by: java.lang.RuntimeException: RESTEASY003940: Unable to instantiate MessageBodyReader
        at org.jboss.resteasy.core.providerfactory.CommonProviders.processProviderContracts(CommonProviders.java:93)
        at org.jboss.resteasy.core.providerfactory.ClientHelper.processProviderContracts(ClientHelper.java:104)
        at org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.processProviderContracts(ResteasyProviderFactoryImpl.java:841)
        at org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.registerProvider(ResteasyProviderFactoryImpl.java:829)
        at org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.registerProvider(ResteasyProviderFactoryImpl.java:816)
        at org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.registerProvider(ResteasyProviderFactoryImpl.java:741)
        at org.jboss.resteasy.core.ResteasyDeploymentImpl.registerProvider(ResteasyDeploymentImpl.java:741)
        at org.jboss.resteasy.core.ResteasyDeploymentImpl.registration(ResteasyDeploymentImpl.java:459)
        at org.jboss.resteasy.core.ResteasyDeploymentImpl.startInternal(ResteasyDeploymentImpl.java:164)
        at org.jboss.resteasy.core.ResteasyDeploymentImpl.start(ResteasyDeploymentImpl.java:121)
        at io.quarkus.resteasy.runtime.standalone.ResteasyStandaloneRecorder.staticInit(ResteasyStandaloneRecorder.java:43)
        at io.quarkus.deployment.steps.ResteasyStandaloneBuildStep$staticInit345281060.deploy_0(Unknown Source)
        at io.quarkus.deployment.steps.ResteasyStandaloneBuildStep$staticInit345281060.deploy(Unknown Source)
        ... 16 more
Caused by: javax.enterprise.inject.CreationException: Synthetic bean instance for com.blazebit.persistence.view.EntityViewManager not initialized yet: com_blazebit_persistence_view_EntityViewManager_3cb728d15a0a04006cc75d03f784feb2bba9a5fb
        - a synthetic bean initialized during RUNTIME_INIT must not be accessed during STATIC_INIT
        - RUNTIME_INIT build steps that require access to synthetic beans initialized during RUNTIME_INIT should consume the SyntheticBeansRuntimeInitBuildItem
        at com.blazebit.persistence.view.EntityViewManager_e7b03adab716ed2bac3c0e8627cad1f71a2d1b56_Synthetic_Bean.create(Unknown Source)
        at com.blazebit.persistence.view.EntityViewManager_e7b03adab716ed2bac3c0e8627cad1f71a2d1b56_Synthetic_Bean.create(Unknown Source)
        at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:111)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:35)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:32)
        at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
        at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
        at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:32)
        at com.blazebit.persistence.view.EntityViewManager_e7b03adab716ed2bac3c0e8627cad1f71a2d1b56_Synthetic_Bean.get(Unknown Source)
        at com.blazebit.persistence.view.EntityViewManager_e7b03adab716ed2bac3c0e8627cad1f71a2d1b56_Synthetic_Bean.get(Unknown Source)
        at io.quarkus.arc.impl.InstanceImpl.getBeanInstance(InstanceImpl.java:223)
        at io.quarkus.arc.impl.InstanceImpl.getInternal(InstanceImpl.java:209)
        at io.quarkus.arc.impl.InstanceImpl.get(InstanceImpl.java:95)
        at com.blazebit.persistence.integration.jaxrs.jsonb.EntityViewMessageBodyReader.init(EntityViewMessageBodyReader.java:113)
        at com.blazebit.persistence.integration.jaxrs.jsonb.EntityViewMessageBodyReader_Bean.create(Unknown Source)
        at com.blazebit.persistence.integration.jaxrs.jsonb.EntityViewMessageBodyReader_Bean.create(Unknown Source)
        at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:111)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:35)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:32)
        at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
        at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
        at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:32)
        at com.blazebit.persistence.integration.jaxrs.jsonb.EntityViewMessageBodyReader_Bean.get(Unknown Source)
        at com.blazebit.persistence.integration.jaxrs.jsonb.EntityViewMessageBodyReader_Bean.get(Unknown Source)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:467)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:480)
        at io.quarkus.arc.impl.ArcContainerImpl$1.get(ArcContainerImpl.java:284)
        at io.quarkus.arc.impl.ArcContainerImpl$1.get(ArcContainerImpl.java:281)
        at io.quarkus.resteasy.common.runtime.QuarkusConstructorInjector.construct(QuarkusConstructorInjector.java:39)
        at org.jboss.resteasy.core.providerfactory.Utils.createProviderInstance(Utils.java:102)
        at org.jboss.resteasy.core.providerfactory.CommonProviders.processProviderContracts(CommonProviders.java:87)
        ... 28 more

I switched to jackson and it worked fine however.

I used these libs in my build.gradle:

implementation 'io.quarkus:quarkus-resteasy-jackson'
runtimeOnly("com.blazebit:blaze-persistence-integration-jaxrs-jackson:1.6.7")

I also realized that the libs defined in the link you gave are not in the quarkus-blaze-persistence-bom: Would it be useful to add these to the bom to keep a uniform version?

Also on the Quarkus Blaze persistence doc, it might be useful to add the link you gave me, unless I misread I haven't seen it. Let me know if you want me to contribute to it.

dubemarcantoine avatar Nov 04 '22 00:11 dubemarcantoine

Actually, by using the blaze-persistence-integration-jaxrs-jsonb package, I got this error:

Well, let's keep this issue for digging into the problem with JSONB. Good that it works for you with Jackson though!

I also realized that the libs defined in the link you gave are not in the quarkus-blaze-persistence-bom: Would it be useful to add these to the bom to keep a uniform version? Also on the Quarkus Blaze persistence doc, it might be useful to add the link you gave me, unless I misread I haven't seen it. Let me know if you want me to contribute to it.

Both of these suggestions sound great. I would very much appreciate any help there!

beikov avatar Nov 04 '22 13:11 beikov