pingidentity / scim2

The UnboundID SCIM 2.0 SDK for Java
175 stars 72 forks source link

Cannot deserialize HTTP error response: JsonbException: Cannot create instance of a class: class com.unboundid.scim2.common.messages.ErrorResponse, No default constructor found. #222

Closed wedgec closed 2 weeks ago

wedgec commented 1 month ago

Description Error responses from SCIM provider cannot be deserialized. Error:

jakarta.json.bind.JsonbException: Cannot create instance of a class: class com.unboundid.scim2.common.messages.ErrorResponse, No default constructor found. at org.eclipse.yasson.internal.deserializer.DefaultObjectInstanceCreator.<init>(DefaultObjectInstanceCreator.java:44) at org.eclipse.yasson.internal.deserializer.DeserializationModelCreator.createObjectDeserializer(DeserializationModelCreator.java:251) at org.eclipse.yasson.internal.deserializer.DeserializationModelCreator.deserializerChainInternal(DeserializationModelCreator.java:193) at org.eclipse.yasson.internal.deserializer.DeserializationModelCreator.deserializerChain(DeserializationModelCreator.java:135) at org.eclipse.yasson.internal.deserializer.DeserializationModelCreator.deserializerChain(DeserializationModelCreator.java:123) at org.eclipse.yasson.internal.DeserializationContextImpl.deserializeItem(DeserializationContextImpl.java:137) at org.eclipse.yasson.internal.DeserializationContextImpl.deserialize(DeserializationContextImpl.java:127) at org.eclipse.yasson.internal.JsonBinding.deserialize(JsonBinding.java:55) at org.eclipse.yasson.internal.JsonBinding.fromJson(JsonBinding.java:102) at org.glassfish.jersey.jsonb.internal.JsonBindingProvider.readFrom(JsonBindingProvider.java:91) at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:235) at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:214) at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:134) at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1072) at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:657) at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:591) at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:298) at org.glassfish.jersey.client.InboundJaxrsResponse$1.call(InboundJaxrsResponse.java:93) at org.glassfish.jersey.internal.Errors.process(Errors.java:292) at org.glassfish.jersey.internal.Errors.process(Errors.java:274) at org.glassfish.jersey.internal.Errors.process(Errors.java:205) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:366) at org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:244) at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:90) at com.unboundid.scim2.client.requests.RequestBuilder.toScimException(RequestBuilder.java:176) at com.unboundid.scim2.client.requests.ReplaceRequestBuilder.invoke(ReplaceRequestBuilder.java:111) at com.unboundid.scim2.client.requests.ReplaceRequestBuilder.invoke(ReplaceRequestBuilder.java:86) ...

To Reproduce I see this across a variety of 4xx responses from different SCIM providers.

Additional context

kqarryzada commented 1 month ago

Hi @wedgec, could you provide some reproduction steps for this issue? It's not clear to me how to recreate this behavior.

From a first glance, I noticed that you're using the JSON-B parser to deserialize the data. The SCIM SDK leverages the Jackson library for serialization and deserialization. Is it possible to update your Spring configuration to use Jackson instead of JSON-B?

wedgec commented 1 month ago

That helps, I'll look into that!

wedgec commented 1 month ago

I found the problem and a fix.

I was using bearer token auth, following the directions in the wiki. The problem is that the jersey-media-json-binding library is a transitive dependency of org.glassfish.jersey.security:oauth2-client, required for OAuth. I excluded the JSON-B library in my gradle build script as follow, and voila!

implementation 'com.unboundid.product.scim2:scim2-sdk-client:3.+'``
implementation ('org.glassfish.jersey.security:oauth2-client:3.+') {
    // Disable JSON-B in SCIM client (in favor of Jackson)
    exclude group: 'org.glassfish.jersey.media', module: 'jersey-media-json-binding'
}

Perhaps you can add this workaround to the wiki?

kqarryzada commented 1 month ago

Thanks for reporting that back. I agree it'd be good to add that to the wiki. I'm also in the process of adding an FAQ section, and I think it would be a good addition there too.

kqarryzada commented 2 weeks ago

I've updated the wiki to clarify this. Thanks again for reporting this issue.