io.github.ralfspoeth.json.Basic Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json Show documentation
Show all versions of json Show documentation
This project implements a JSON parser and serializer
which operates around immutable data structures for
the JSON elements.
package io.github.ralfspoeth.json;
public sealed interface Basic extends Element permits JsonBoolean, JsonNull, JsonNumber, JsonString {
String json();
T value();
static Basic> of(Object o) {
return switch(o) {
case null -> JsonNull.INSTANCE;
case Boolean b -> JsonBoolean.of(b);
case Double d -> ofDouble(d);
case Float f -> ofDouble(f);
case Number n -> ofDouble(n.doubleValue());
default -> ofString(o.toString());
};
}
private static JsonNumber ofDouble(double d) {
return new JsonNumber(d);
}
private static JsonString ofString(String s) {
return new JsonString(s);
}
}