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 optReader;
public OptionalDecoder(final JsonReader.ReadObject reader) {
if (reader == null) throw new IllegalArgumentException("reader can't be null");
this.optReader = reader;
}
@Override
public Optional read(JsonReader reader) throws IOException {
if (reader.wasNull()) return Optional.empty();
return Optional.ofNullable(optReader.read(reader));
}
}