public int getSize(Serializable ser) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ser);
oos.close();
return baos.size();
}
或使用
ObjectSizeCalculator.getObjectSize(dto);
可能会报错:
Could not initialize class jdk.nashorn.internal.ir.debug.ObjectSizeCalculator$CurrentLayout