-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Automatically detect target type (Class
) to deserialize to
#5064
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
Comments
https://github.com/rohanlopes20/jackson-databind-auto-detect-class Created this fork for same. |
For me, this looks potentially useful. Don't change yet but it might be better to target master branch instead of 2.19 branch. The master branch uses different package names (tools.jackson instead of com.fasterxml.jackson). The tests need to be improved. Assert the values in the bean not just that it isn't null. More tests needed too. |
@cowtowncoder most of the code is copied from a Mockito PR. This has licensing implications. In the ASF, we would require that the LICENSE file is updated to include the MIT license from Mockito. Something along the licenses of saying that source file X has code copied from Mockito under the MIT License and then paste in the license. |
Hmmh. The last thing I want to import are license hassles. MIT is more permissive so it should be ok but... I guess as long as PR contains changes. Also: same auto-detection should be, I think, added to |
Forgot to mention: yes, if this works without adding complications for existing overloads, this seems like a very nice ergonomic improvement. |
Good one! Like we have in Kotlin extension. |
FYI, we have several readValue methods that we can apply this solution. |
@rohanlopes20 Just wondering, are you planning on contributing? :))) Seems like you almost have it. |
Yes, I am checking reader code based on above comment. I saw some methods which can use this but seems like there are no test cases for same. Also, can you let me know what else is required in tests other than checking not null objects? @cowtowncoder @JooHyukKim |
@cowtowncoder Saw ObjectReader code, not sure if my understanding is correct but below 1st method is public.
If below code added to handle autodetection then it directly refers to code block above(1st method ObjectReader#readValue(InputStream src) instead of reified code. In this case we have to make it private. Pretty sure that is incorrect(testSerializeAsExternalizable this test fails too).
Can you please guide what needs to be done ? Don't want to break jackson standards. You can commit in fork if required. https://github.com/rohanlopes20/jackson-databind-auto-detect-class |
If we do this for Jackson 3, we could just remove the existing |
I did that but it broke test case testSerializeAsExternalizable. |
And where is the failing test result? Let's write a PR so we can all see what's going on |
org.opentest4j.AssertionFailedError: |
Ahhh. I forgot the basic thing about So I think type detection wrt
then something like
if that is possible -- and importantly, if that is actually usable from caller perspective. Does this make more sense? |
If that is the case then will revert changes for other readValue methods. For above case below works -
Test Case
|
@cowtowncoder @JooHyukKim Can you check and revert please. |
Class
) to deserialize to
Is your feature request related to a problem? Please describe.
Currently to deserialize object in ObjectMapper we use below syntax -
Can ObjectMapper automatically detect the class to be deserialized based on the return type?
This is already implemented in Mockito mockito/mockito#2779
Describe the solution you'd like
Below method can be added in ObjectMapper class to detect class automatically.
Usage example
Additional context
No response
The text was updated successfully, but these errors were encountered: