-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
After upgrading to 2.11.1 from 2.11.0, code that uses a copied ObjectMapper, that then registers subtypes does not work.
Take this simple test case:
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
public class JacksonPolymorphicTest {
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "packetType")
public interface A {
}
@JsonTypeName("myType")
static class B implements A {
}
@Test
void test() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper().copy();
objectMapper.getSubtypeResolver().registerSubtypes(B.class);
String json = "{ \"packetType\": \"myType\" }";
objectMapper.readValue(json, A.class);
}
}
The above test passes by changing one of two things:
- Remove the
.copy()
from the ObjectMapper line - Use Jackson 2.11.0 instead of 2.11.1
Also, I'm aware that the above code does not serialize, but that's not the point right now. I'm just worried about deserialization.
I'm not really sure what the cause is here, but it's something that changed from 2.11.0 to 2.11.1. Maybe it's also affecting other times when the ObjectMapper is copied?
EDIT: This line changed from 2.11.0 to 2.11.1:
_subtypeResolver = src._subtypeResolver.copy(); |
This may have been affected by changes from: #2755
Metadata
Metadata
Assignees
Labels
No labels