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

Added type match check to read functions #937

Merged
merged 10 commits into from
Apr 12, 2025
Merged

Conversation

k163377
Copy link
Contributor

@k163377 k163377 commented Apr 6, 2025

Fixed a problem with functions such as readValue that could return null even if non-null was specified in Kotlin.
This fix will close #399 .

Copy link
Contributor Author

@k163377 k163377 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cowtowncoder @JooHyukKim
Could you please help me with a review of the exceptions to be thrown?

inline fun <reified T> ObjectMapper.readValue(jp: JsonParser): T = readValue(jp, jacksonTypeRef<T>())
inline fun <reified T> ObjectMapper.readValues(jp: JsonParser): MappingIterator<T> = readValues(jp, jacksonTypeRef<T>())
.checkTypeMismatch()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, there is an overhead of generating a TypeReference each time, and this change adds another overhead of checking.
Therefore, after checking benchmarks, I will add a document to avoid using it in situations where performance is important.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If performance is issue.... would simple try-catch instead of this type check(this PR) have better performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, I confirmed that there was already an 8% drop in throughput before the change.
https://github.com/k163377/read-value-benchmark/blob/master/reports/results.csv

The throughput is high enough to begin with, so I don't think the performance of this function will be an issue in basic use cases.
However, I am considering giving only comments for use cases that require extreme performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a little more consideration, I decided not to make a performance statement because it is unlikely that the overhead of this function will actually dominate.
371a858

@k163377 k163377 requested a review from Copilot April 7, 2025 08:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (6)
  • src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt: Language not supported
  • src/test/kotlin/com/fasterxml/jackson/module/kotlin/ReadValueTest.kt: Language not supported
  • src/test/kotlin/com/fasterxml/jackson/module/kotlin/ReadValuesTest.kt: Language not supported
  • src/test/kotlin/com/fasterxml/jackson/module/kotlin/TestCommons.kt: Language not supported
  • src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/WithoutCustomDeserializeMethodTest.kt: Language not supported
  • src/test/kotlin/com/fasterxml/jackson/module/kotlin/kogeraIntegration/deser/valueClass/deserializer/SpecifiedForObjectMapperTest.kt: Language not supported

@k163377 k163377 changed the title 【WIP】Added type match check to read functions Added type match check to read functions Apr 12, 2025
@k163377 k163377 merged commit 5286933 into FasterXML:2.19 Apr 12, 2025
15 checks passed
@k163377 k163377 deleted the 399 branch April 12, 2025 09:37
k163377 added a commit that referenced this pull request Apr 12, 2025
Fix for doc added in #937
k163377 added a commit to ProjectMapK/jackson-module-kogera that referenced this pull request Apr 12, 2025
k163377 added a commit to ProjectMapK/jackson-module-kogera that referenced this pull request Apr 12, 2025
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.

[BUG] ObjectMapper.readValue<T>(...) breaks null safety
3 participants