-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Open
Labels
Description
Description
(Idea by @eamonnmcmanus )
We want to build a JsonObject/Array in a simple way like:
Map<String, Object> user = Map.of(
"id", 1001,
"name", "Alice",
"age", 25,
"tags", List.of("Java", "Kotlin", "Scala"),
"address", Map.of("city", "Shanghai", "street", "Xujiahui")
);
JsonObject userJson = JsonObject.parse(user);However, because of Java's type system, we can only do:
// JsonObject.class
static JsonObject parse(Map<String, ?>)
static JsonObject of(Map<String, ? extends JsonElement>)
// JsonArray.class
static JsonArray parse(Iterable<?>)
static JsonArray of(Iterable<? extends JsonElement>)
// JsonPrimitive
static JsonPrimitive parse(Object) // ???
// JsonElelement
static JsonElement parse(Object)