jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

Autodetect classes in ObjectMapper

Open rohanlopes20 opened this issue 7 months ago • 5 comments

https://github.com/FasterXML/jackson-databind/issues/5064

rohanlopes20 avatar Apr 06 '25 06:04 rohanlopes20

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.

yawkat avatar Apr 07 '25 10:04 yawkat

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

JooHyukKim avatar Apr 09 '25 11:04 JooHyukKim

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

rohanlopes20 avatar Apr 11 '25 09:04 rohanlopes20

@cowtowncoder can you check above.

rohanlopes20 avatar Apr 20 '25 16:04 rohanlopes20

@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)

cowtowncoder avatar Apr 20 '25 22:04 cowtowncoder