All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.ralfspoeth.json.Basic Maven / Gradle / Ivy

Go to download

This project implements a JSON parser and serializer which operates around immutable data structures for the JSON elements.

There is a newer version: 1.1.6
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy