diff --git a/serializers/src/main/java/io/pravega/schemaregistry/serializers/WithSchema.java b/serializers/src/main/java/io/pravega/schemaregistry/serializers/WithSchema.java index a28853f67..25b0b9d19 100644 --- a/serializers/src/main/java/io/pravega/schemaregistry/serializers/WithSchema.java +++ b/serializers/src/main/java/io/pravega/schemaregistry/serializers/WithSchema.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Preconditions; import com.google.protobuf.DescriptorProtos; import com.google.protobuf.DynamicMessage; import com.google.protobuf.GeneratedMessageV3; @@ -212,6 +213,8 @@ private static String toJsonString(SerializationFormat format, Object deserializ * @return A WithSchema object which has Avro Schema and the corresponding object. */ public static WithSchema avro(T object, AvroSchema avroSchema) { + Preconditions.checkNotNull(object, "object cannot be null"); + Preconditions.checkNotNull(avroSchema, "schema cannot be null"); return new WithSchema<>(avroSchema.getSchemaInfo(), object, (x, y) -> object); } @@ -224,6 +227,8 @@ public static WithSchema avro(T object, AvroSchema avroSchema) { * @return A WithSchema object which has Protobuf Schema and the corresponding object. */ public static WithSchema proto(T object, ProtobufSchema protobufSchema) { + Preconditions.checkNotNull(object, "object cannot be null"); + Preconditions.checkNotNull(protobufSchema, "schema cannot be null"); return new WithSchema<>(protobufSchema.getSchemaInfo(), object, (x, y) -> object); } @@ -236,6 +241,8 @@ public static WithSchema proto(T object, Proto * @return A WithSchema object which has Json schema and the corresponding object. */ public static WithSchema json(T object, JSONSchema jsonSchema) { + Preconditions.checkNotNull(object, "object cannot be null"); + Preconditions.checkNotNull(jsonSchema, "schema cannot be null"); return new WithSchema<>(jsonSchema.getSchemaInfo(), object, (x, y) -> object); } }