Skip to content

Commit

Permalink
Precondition
Browse files Browse the repository at this point in the history
Signed-off-by: Shivesh Ranjan <[email protected]>
  • Loading branch information
shiveshr committed Jul 17, 2020
1 parent ba0928d commit 5bd4e63
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <T> WithSchema<T> avro(T object, AvroSchema<T> avroSchema) {
Preconditions.checkNotNull(object, "object cannot be null");
Preconditions.checkNotNull(avroSchema, "schema cannot be null");
return new WithSchema<>(avroSchema.getSchemaInfo(), object, (x, y) -> object);
}

Expand All @@ -224,6 +227,8 @@ public static <T> WithSchema<T> avro(T object, AvroSchema<T> avroSchema) {
* @return A WithSchema object which has Protobuf Schema and the corresponding object.
*/
public static <T extends GeneratedMessageV3> WithSchema<T> proto(T object, ProtobufSchema<T> protobufSchema) {
Preconditions.checkNotNull(object, "object cannot be null");
Preconditions.checkNotNull(protobufSchema, "schema cannot be null");
return new WithSchema<>(protobufSchema.getSchemaInfo(), object, (x, y) -> object);
}

Expand All @@ -236,6 +241,8 @@ public static <T extends GeneratedMessageV3> WithSchema<T> proto(T object, Proto
* @return A WithSchema object which has Json schema and the corresponding object.
*/
public static <T> WithSchema<T> json(T object, JSONSchema<T> jsonSchema) {
Preconditions.checkNotNull(object, "object cannot be null");
Preconditions.checkNotNull(jsonSchema, "schema cannot be null");
return new WithSchema<>(jsonSchema.getSchemaInfo(), object, (x, y) -> object);
}
}

0 comments on commit 5bd4e63

Please sign in to comment.