File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed
main/kotlin/io/github/projectmapk/jackson/module/kogera
test/kotlin/io/github/projectmapk/jackson/module/kogera/zPorted Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -82,10 +82,19 @@ internal inline fun <reified T> Any?.checkTypeMismatch(): T {
8282public inline fun <reified T > ObjectMapper.readValue (jp : JsonParser ): T = readValue(jp, jacksonTypeRef<T >())
8383 .checkTypeMismatch()
8484
85- // TODO: After importing 2.19, import the changes in kotlin-module and uncomment the tests.
86- public inline fun <reified T > ObjectMapper.readValues (
87- jp : JsonParser
88- ): MappingIterator <T > = readValues(jp, jacksonTypeRef<T >())
85+ /* *
86+ * Shorthand for [ObjectMapper.readValues].
87+ * @throws RuntimeJsonMappingException Especially if [T] is non-null and the value read is null.
88+ * Other cases where the read value is of a different type than [T]
89+ * due to an incorrect customization to [ObjectMapper].
90+ */
91+ public inline fun <reified T > ObjectMapper.readValues (jp : JsonParser ): MappingIterator <T > {
92+ val values = readValues(jp, jacksonTypeRef<T >())
93+
94+ return object : MappingIterator <T >(values) {
95+ override fun nextValue (): T = super .nextValue().checkTypeMismatch()
96+ }
97+ }
8998
9099/* *
91100 * Shorthand for [ObjectMapper.readValue].
Original file line number Diff line number Diff line change @@ -38,9 +38,7 @@ class ReadValuesTest {
3838 val itr = mapper.readValues<String >(src)
3939
4040 assertEquals(" foo" , itr.next())
41- // TODO: It is expected to be checked after importing 2.19.
42- // assertThrows<RuntimeJsonMappingException> {
43- assertDoesNotThrow {
41+ assertThrows<RuntimeJsonMappingException > {
4442 itr.next()
4543 }
4644 }
@@ -51,9 +49,7 @@ class ReadValuesTest {
5149 val itr = mapper.readValues<String >(src)
5250
5351 assertEquals(" foo" , itr.nextValue())
54- // TODO: It is expected to be checked after importing 2.19.
55- // assertThrows<RuntimeJsonMappingException> {
56- assertDoesNotThrow {
52+ assertThrows<RuntimeJsonMappingException > {
5753 itr.nextValue()
5854 }
5955 }
You can’t perform that action at this time.
0 commit comments