google / gson

A Java serialization/deserialization library to convert Java Objects into JSON and back
Apache License 2.0
23.16k stars 4.27k forks source link

Guarantee that `JsonElement.toString()` produces JSON #2659

Closed Marcono1234 closed 2 months ago

Marcono1234 commented 4 months ago

(Depends on #2654)

Purpose

Resolves #591 Resolves #1439

Description

As pointed out in #591 the result of JsonElement.toString() is currently unspecified. However, many users and also Gson's own unit tests assume that the output is valid JSON.

Changing the JsonElement.toString() behavior would likely be backward incompatible. Therefore it seems reasonable to guarantee in the documentation that toString() produces JSON, which is already the case implementation-wise.

Checklist