Skip to content

Doesn't work with @JsonCreator #50

Open

Description

@jakub-bochenski

Trying to deserialize this class fails

@Resource
public class JavaLabel {

    @Link
    public HALLink self;
    public String name;

    @JsonCreator
    public JavaLabel(
            @JsonProperty("self") HALLink self,
            @JsonProperty("name") String name)
    {
        this.self = self;
        this.name = name;
    }
}
 com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Invalid definition for property 'f6de7aa6-e521-4da7-8104-9495ebf67f6b:self' (of type `com.zoovu.permissions.db.JavaLabel`): Could not find creator property with name 'f6de7aa6-e521-4da7-8104-9495ebf67f6b:self' (known Creator properties: [self, name])
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 2]
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:62)
	at com.fasterxml.jackson.databind.DeserializationContext.reportBadPropertyDefinition(DeserializationContext.java:1883)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:636)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:277)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:151)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:471)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:415)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:317)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:284)
	at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:174)
	at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:669)
	at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:5048)
	at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:4893)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3036)

Activity

  1. arucard21 commented on Jan 20, 2025

    @arucard21
    Collaborator

    I don't think this repo is really maintained anymore, and I don't use this library myself either. But from the stacktrace, it looks like it has a property f6de7aa6-e521-4da7-8104-9495ebf67f6b:self which it can't deserialize. Assuming you don't have that exact property name in your original JSON document, the UUID prefix looks like it might be a CURIE prefix. The example Java object you provided doesn't seem to have CURIEs defined so I'm not sure how that would be added. Do you use CURIEs which you didn't include in this example?

    It seems unlikely that it will help but you could try to explicitly set the name of the self variable in the @Link annotation as well.

    @Link("self")
    public HALLink self;

    But this library might indeed not work with @JsonCreator. The way the deserialization seems to work (in HALBeanDeserializer.java) is that it modifies the fields in _links and _embedded in the deserializer. Then it just passes it back to the original deserializer. So maybe the way it's modified doesn't work with @JsonCreator. But given the lack of maintenance on this library, it seems unlikely that that will be fixed.

  2. jakub-bochenski commented on Jan 20, 2025

    @jakub-bochenski
    Author

    The way the deserialization seems to work (in HALBeanDeserializer.java) is that it modifies the fields in _links and _embedded in the deserializer. Then it just passes it back to the original deserializer. So maybe the way it's modified doesn't work with @jsoncreator. But given the lack of maintenance on this library, it seems unlikely that that will be fixed.

    Yeah, the f6de7aa6-e521-4da7-8104-9495ebf67f6b:self comes from the library renaming the properties by prefixing them with an UUID, to apply special processing.
    Part of this processing doesn't activate for @jsoncreator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions