Skip to content

Autodetect classes in ObjectMapper #5071

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

Open
wants to merge 6 commits into
base: 3.x
Choose a base branch
from

Conversation

rohanlopes20
Copy link

@yawkat
Copy link
Member

yawkat commented Apr 7, 2025

I'm not a fan of this change. It is a hack to work around language limitations. It makes all sorts of invalid readValue calls compile (e.g. nonsense like mapper.readValue("\"foo\"", "java.lang.String")), leading to confusing compile or runtime errors. It also breaks in more complex scenarios with generic parameters, e.g. <T> T myReadMethod(InputStream stream) { return mapper.readValue(stream); } or when deserializing parameterized types. In my opinion, this makes the API more complex and does not justify saving a few characters to specify the type.

@JooHyukKim
Copy link
Member

@yawkat has valid point. And also ObjectWriter/ObjectReader in mind, we shod be careful to not add up big complexity or API inconsistency.

@rohanlopes20
Copy link
Author

@yawkat 's point make sense. Let me know if we can ignore this or need more discussion. @JooHyukKim @cowtowncoder

@rohanlopes20
Copy link
Author

@cowtowncoder can you check above.

@cowtowncoder
Copy link
Member

@rohanlopes20 I think I'll need to postpone this a bit, consider post 2.19.0. I think it does require more discussion. I like the idea, but I think @yawkat's concerns are valid.

We could, for example, consider alternate method name instead of overload. Like, maybe

ObjectMapper.read(InputStream)

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

Successfully merging this pull request may close these issues.

4 participants