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

Polymorphic subtypes not registering on copied ObjectMapper (2.11.1) #2785

Closed
retrodaredevil opened this issue Jul 4, 2020 · 3 comments
Closed
Milestone

Comments

@retrodaredevil
Copy link

retrodaredevil commented Jul 4, 2020

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

@cowtowncoder
Copy link
Member

Thank you for reporting this, and especially for investigation and fix! It is unfortunate that the fix to copy problem lead to this regression.

I'll have a look at PR to verify it (sounds legit). One other thing I will need to be able to merge PR is CLA:

https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

(unless I have asked and received one earlier; one is good for all contributions)

which is easiest to print, fill & sign, scan/photo, email to info at fasterxml dot com.
Once I get it, I can merge the PR and get in for 2.11.2.

@retrodaredevil
Copy link
Author

Ok, I emailed the CLA to info@fasterxml.com.

@cowtowncoder
Copy link
Member

Thank you! I merged PR changes manually, and the fix will be included in 2.11.2 (which unfortunately will take a while as 2.11.1 was just released -- but 2.12.2-SNAPSHOT is available via Sonatype's OSS repo)

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