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

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

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

import net.hamnaberg.json.Json;

import java.util.Optional;

final class DefaultJsonCodec implements JsonCodec {
    private final String toString;
    private final DecodeJson decoder;
    private final EncodeJson encoder;

    DefaultJsonCodec(DecodeJson decoder, EncodeJson encoder) {
        this(decoder, encoder, String.format("DefaultCodec(decoder=%s, encoder=%s)", decoder, encoder));
    }

    DefaultJsonCodec(DecodeJson decoder, EncodeJson encoder, String toString) {
        this.decoder = decoder;
        this.encoder = encoder;
        this.toString = toString;
    }

    @Override
    public DecodeResult fromJson(Json.JValue value) {
        return decoder.fromJson(value);
    }

    @Override
    public Json.JValue toJson(A value) {
        return encoder.toJson(value);
    }

    @Override
    public Optional defaultValue() {
        return decoder.defaultValue();
    }

    public String toString() {
        return toString;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy