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

net.hamnaberg.json.codec.EncodeJson Maven / Gradle / Ivy

The newest version!
package net.hamnaberg.json.codec;

import net.hamnaberg.json.Json;

import java.util.List;
import java.util.Optional;
import java.util.function.Function;

public interface EncodeJson {
    Json.JValue toJson(A value);

    @Deprecated
    default Json.JValue toJsonUnsafe(A value) {
        return toJson(value);
    }

    default  EncodeJson contramap(Function f) {
        return value -> this.toJson(f.apply(value));
    }

    default FieldEncoder fieldEncoder(String name) {
        return FieldEncoder.typedFieldOf(name, this);
    }

    default EncodeJson> option() {
        return Encoders.optionalencoder(this);
    }

    default EncodeJson> list() {
        return Encoders.listEncoder(this);
    }
}