com.codepoetics.octarine.json.deserialisation.ValidRecordDeserialiser Maven / Gradle / Ivy
package com.codepoetics.octarine.json.deserialisation;
import com.codepoetics.octarine.records.Record;
import com.codepoetics.octarine.records.RecordValidationException;
import com.codepoetics.octarine.records.Schema;
import com.codepoetics.octarine.records.Validation;
import com.fasterxml.jackson.core.JsonParser;
import java.io.Reader;
class ValidRecordDeserialiser implements Deserialiser> {
private final Schema schema;
private final RecordDeserialiser reader;
ValidRecordDeserialiser(Schema schema, RecordDeserialiser reader) {
this.schema = schema;
this.reader = reader;
}
@Override
public Validation apply(JsonParser parser) {
try {
return validated(reader.apply(parser));
} catch (RecordValidationException e) {
return e.toValidation();
}
}
@Override
public Validation fromReader(Reader reader) {
try {
return validated(this.reader.fromReader(reader));
} catch (RecordValidationException e) {
return e.toValidation();
}
}
private Validation validated(Record record) {
return schema.validate(record);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy