Skip to content

Subclassed Throwable deserialization fails since v2.18.0 - no creator index for property 'cause' #4827

Closed
@nilswieber

Description

@nilswieber

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

The deserialization of Throwables fails if they are subclassed without a no-arg constructor.

Version Information

Seems to affect versions 2.18.0 - 2.18.2

Reproduction

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class SubclassedExceptionJava extends Exception {
    @JsonCreator
    SubclassedExceptionJava(@JsonProperty("message") String message, @JsonProperty("cause") Throwable cause){
        super(message, cause);
    }


    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper()
                .configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        SubclassedExceptionJava exceptionToSerialize = new SubclassedExceptionJava("Test Message", null);
        String serialized = mapper.writeValueAsString(exceptionToSerialize);

        System.out.println(serialized);
        
        mapper.readValue(serialized, SubclassedExceptionJava.class);
        //Exception in thread "main" java.lang.IllegalStateException: Internal error: no creator index for property 'cause' (of type com.fasterxml.jackson.databind.deser.impl.MethodProperty)
    }
}

The following exception is thrown:

Exception in thread "main" java.lang.IllegalStateException: Internal error: no creator index for property 'cause' (of type com.fasterxml.jackson.databind.deser.impl.MethodProperty)
	at com.fasterxml.jackson.databind.deser.SettableBeanProperty.getCreatorIndex(SettableBeanProperty.java:450)
	at com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer.assignParameter(PropertyValueBuffer.java:363)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:449)
	at com.fasterxml.jackson.databind.deser.std.ThrowableDeserializer.deserializeFromObject(ThrowableDeserializer.java:85)
	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.ObjectMapper._readMapAndClose(ObjectMapper.java:4917)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3860)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3828)
	at SubclassedExceptionJava.main(SubclassedExceptionJava.java:21)

Expected behavior

In versions before 2.18.0 the described code worked flawlessly and the Exception is parsed.

Additional context

If a no arg constructor is added, the example works (even for versions 2.18.0 - 2.18.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.18Issues planned at 2.18 or later

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions