Skip to content
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

Customizing Jackson deserialization to ignore unknown properties does not work for ErrorResponse #236

Open
wedgec opened this issue Dec 17, 2024 · 1 comment
Assignees

Comments

@wedgec
Copy link

wedgec commented Dec 17, 2024

Description
This is related to Issue 81. I am working with a SCIM provider that includes non-standard attributes on their urn:ietf:params:scim:api:messages:2.0:Error objects, causing deserialization to fail. I tried customizing deserialization by setting JsonUtils' MapperFactory, but to no effect.

To Reproduce
Here's a code snippet for reproducing issue. Note the non-standard attributes in the ErrorResponse JSON, code, entity_id, and message.

String errorResponseJson =
    """
        {
            "code": "uniqueness",
            "entity_id": "thanh.veum",
            "message": "Another user already exists with this username 'thanh.veum'",
            "detail": "Another user already exists with this username 'thanh.veum'",
            "schemas": [
                "urn:ietf:params:scim:api:messages:2.0:Error"
            ],
            "status": 409
        }""";

MapperFactory factory = new MapperFactory();
factory.setDeserializationCustomFeatures(Map.of(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false));
JsonUtils.setCustomMapperFactory(factory);

// Throws exception
JsonUtils
    .getObjectReader()
    .forType(ErrorResponse.class)
    .readValue(errorResponseJson);

Here's the stack trace that results:

Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Core attribute message is undefined for schema urn:ietf:params:scim:api:messages:2.0:Error
	at com.fasterxml.jackson.databind.deser.SettableAnyProperty._throwAsIOE(SettableAnyProperty.java:304)
	at com.fasterxml.jackson.databind.deser.SettableAnyProperty.set(SettableAnyProperty.java:267)
	at com.fasterxml.jackson.databind.deser.impl.PropertyValue$Any.assign(PropertyValue.java:101)
	at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:223)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:453)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1497)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:348)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)
	at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
	at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2125)
	at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1566)
	at scratch.Scratch.main(Scratch.java:35)
Caused by: com.unboundid.scim2.common.exceptions.BadRequestException: Core attribute message is undefined for schema urn:ietf:params:scim:api:messages:2.0:Error
	at com.unboundid.scim2.common.exceptions.BadRequestException.invalidSyntax(BadRequestException.java:270)
	at com.unboundid.scim2.common.BaseScimResource.setAny(BaseScimResource.java:231)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at com.fasterxml.jackson.databind.introspect.AnnotatedMethod.callOnWith(AnnotatedMethod.java:118)
	at com.fasterxml.jackson.databind.deser.SettableAnyProperty$MethodAnyProperty._set(SettableAnyProperty.java:363)
	at com.fasterxml.jackson.databind.deser.SettableAnyProperty.set(SettableAnyProperty.java:263)
	... 10 more
Caused by: com.unboundid.scim2.common.exceptions.BadRequestException: Core attribute message is undefined for schema urn:ietf:params:scim:api:messages:2.0:Error

Expected behavior
I would expect deserialization to succeed, with the resulting Java object constructed on the basis on the standard attributes only.

Additional context

  • Jackson version: 2.18.2
  • SCIM 2 SDK version: 3.2.0
@kqarryzada kqarryzada self-assigned this Jan 17, 2025
@kqarryzada
Copy link
Collaborator

Hi @wedgec, apologies that I haven't gotten a chance to look at this yet. I will try to reproduce this next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants