// 将schema转换为字节数组
val schemaBytes: Array[Byte] = schema.toString.getBytes(StandardCharsets.UTF_8)
// 将字节数组包装为可序列化的对象
val serializableSchemaBytes: SerializableBytes = new SerializableBytes(schemaBytes)
// 将字节数组反序列化为schema对象
val schemaString = new String(serializableSchemaBytes.bytes, StandardCharsets.UTF_8)
val schema = new Schema.Parser().parse(schemaString)
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream, Serializable}
class SerializableBytes(val bytes: Array[Byte]) extends Serializable {
private def writeObject(out: ObjectOutputStream): Unit = {
out.writeInt(bytes.length)
out.write(bytes)
}
private def readObject(in: ObjectInputStream): Unit = {
val length = in.readInt()