File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -102,11 +102,12 @@ inline fun <reified T : Any> File.readValue(): T =
102102 */
103103inline fun <reified T : Any > File.readValueOrNull (): T ? {
104104 val mapper = mapper()
105- val parser = mapper.factory.createParser(this )
106105
107- val values = mapper.readValues<T >(parser).readAll().also {
108- if (it.isEmpty()) return null
109- if (it.size > 1 ) throw IOException (" Multiple top-level objects found in file '$this '." )
106+ val values = mapper.factory.createParser(this ).use { parser ->
107+ mapper.readValues<T >(parser).readAll().also {
108+ if (it.isEmpty()) return null
109+ if (it.size > 1 ) throw IOException (" Multiple top-level objects found in file '$this '." )
110+ }
110111 }
111112
112113 return values.first()
You can’t perform that action at this time.
0 commit comments