Skip to content

TypeAdapter to read "raw" json value #1368

Open
@tmm1

Description

@tmm1

Since #667 JsonWriter#jsonValue() allows emitting a raw json blob when generating json.

I'd like the equivalent for parsing json. In my case, I have large/complex json sub-trees that I would like to avoid parsing to save cpu/allocations. But I still need the value so I can re-create the original json if needed.

Currently I use a typeadapter as so:

class RawJsonAdapter: TypeAdapter<String>() {
    override fun write(out: JsonWriter?, value: String?) {
        out?.jsonValue(value)
    }
    override fun read(reader: JsonReader?): String {
        return JsonParser().parse(reader).toString()
    }
}

However the entire subtree has to be first parsed, and then re-serialized to json before I end up with the raw value.

Is there a more performant way to implement my TypeAdapter#read here?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions