Skip to content

About the difference between toString() and getAsString() in JsonPrimitive #1439

@devonkey

Description

@devonkey

Is the code output reasonable?

def main(args: Array[String]): Unit = {
    val e = new JsonPrimitive("zz")
    println(e)
    println(e.getAsString)
    println(new JsonPrimitive(e.toString))
    println(new JsonPrimitive(new JsonPrimitive(e.toString).toString))
  }
result :
"zz"
zz
"\"zz\""
"\"\\\"zz\\\"\""

I think the com.google.gson.streamJsonWrite.string(value:String) is fine as a child element, but it's worth pondering when we use toString() for an independent JsonPrimitive object.

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