Skip to content

Jackson 3: JsonParser.readAsValues gone - what to use instead? #1485

@modular-music-and-code

Description

@modular-music-and-code

In Jackson 3, JsonParser.readAsValues was removed.
I was using Jackson 2 to stream-read a huge number of POJOs from a Reader.
They were separated by newlines. It worked.

The reading happened in a streamed way: neither input data nor output data was pre-stored.
I had empirically proven it, by reading billions of items in a very limited Java-heap.

Now I need an alternative solution.
Is is still somehow possible in Jackson 3?

Pseudo-code of my Jackson 2 solution (I could not quickly extract real code from the actual project)

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@T")
data class MyPOJO(val s: String, val b: Boolean)

// NOTE: POJOs separated by newlines - and, this time I use String instead of Reader to simplify the example
val text: String = """
	{"@T":"MyPOJO","s":"item-1","b":true}
	{"@T":"MyPOJO","s":"item-2","b":true}
	{"@T":"MyPOJO","s":"item-3","b":true}
"""

val parser: JsonParser = /* ... */
val iterator: Iterator<MyPOJO> = parser.readValuesAs(MyPOJO::class.java)
// "iterator" contained 3 POJOs, correctly deserialized

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions