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

net.hamnaberg.json.JsonCodec Maven / Gradle / Ivy

There is a newer version: 8.0.0
Show newest version
package net.hamnaberg.json;

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

public interface JsonCodec extends EncodeJson, DecodeJson {
    default  JsonCodec xmap(Function f1, Function f2) {
        JsonCodec that = this;
        return new JsonCodec() {
            @Override
            public Optional fromJson(Json.JValue value) {
                return that.fromJson(value).map(f1);
            }

            @Override
            public Optional toJson(B value) {
                return that.toJson(f2.apply(value));
            }
        };
    }
}