com.dslplatform.json.runtime.OptionalDecoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dsl-json-java8 Show documentation
Show all versions of dsl-json-java8 Show documentation
DSL Platform compatible Java JSON library (https://dsl-platform.com)
package com.dslplatform.json.runtime;
import com.dslplatform.json.JsonReader;
import java.io.IOException;
import java.util.Optional;
public final class OptionalDecoder implements JsonReader.ReadObject> {
private final JsonReader.ReadObject decoder;
public OptionalDecoder(final JsonReader.ReadObject decoder) {
if (decoder == null) throw new IllegalArgumentException("decoder can't be null");
this.decoder = decoder;
}
@Override
public Optional read(JsonReader reader) throws IOException {
if (reader.wasNull()) return Optional.empty();
return Optional.ofNullable(decoder.read(reader));
}
}