net.hamnaberg.json.codec.FieldEncoder 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 final class FieldEncoder {
public final String name;
public final EncodeJson encoder;
private FieldEncoder(String name, EncodeJson encoder) {
this.name = name;
this.encoder = encoder;
}
@Override
public String toString() {
return String.format("FieldDecoder(%s)", name);
}
public FieldEncoder contramap(Function f) {
return typedFieldOf(name, encoder.contramap(f));
}
public Json.JValue toJson(A value) {
return encoder.toJson(value);
}
public static FieldEncoder EString(String name) {
return typedFieldOf(name, Encoders.EString);
}
public static FieldEncoder EInt(String name) {
return typedFieldOf(name, Encoders.EInt);
}
public static FieldEncoder EDouble(String name) {
return typedFieldOf(name, Encoders.EDouble);
}
public static FieldEncoder ELong(String name) {
return typedFieldOf(name, Encoders.ELong);
}
public static FieldEncoder EBoolean(String name) {
return typedFieldOf(name, Encoders.EBoolean);
}
public static FieldEncoder
© 2015 - 2024 Weber Informatics LLC | Privacy Policy