com.datastrato.gravitino.EntitySerDe Maven / Gradle / Ivy
/*
* Copyright 2023 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino;
import java.io.IOException;
import java.util.Optional;
public interface EntitySerDe {
/**
* Serializes the entity to a byte array.
*
* @param t the entity to serialize
* @return the serialized byte array of the entity
* @param The type of entity
* @throws IOException if the serialization fails
*/
byte[] serialize(T t) throws IOException;
/**
* Deserializes the entity from a byte array.
*
* @param bytes the byte array to deserialize
* @param clazz the class of the entity
* @return the deserialized entity
* @param The type of entity
* @throws IOException if the deserialization fails
*/
default T deserialize(byte[] bytes, Class clazz) throws IOException {
ClassLoader loader =
Optional.ofNullable(Thread.currentThread().getContextClassLoader())
.orElse(getClass().getClassLoader());
return deserialize(bytes, clazz, loader);
}
/**
* Deserializes the entity from a byte array.
*
* @param bytes the byte array to deserialize
* @param clazz the class of the entity
* @param classLoader the class loader to use
* @return the deserialized entity
* @param The type of entity
* @throws IOException if the deserialization fails
*/
T deserialize(byte[] bytes, Class clazz, ClassLoader classLoader)
throws IOException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy