Yes, the compression should work for java.io.Externalizable as well.
See the following test:
Note that I am using the private API here. It is not to be used on production but just to show that it works.
public static class Test implements Externalizable {
private long a;
private long b;
private long c;
private long d;
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeLong(a);
out.writeLong(b);
out.writeLong(c);
out.writeLong(d);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
a = in.readLong();
b = in.readLong();
c = in.readLong();
d = in.readLong();
}
}
public static void main(String[] args) throws InterruptedException {
{
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.setEnableCompression(true);
SerializationService serializationService = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
System.out.println("COMPRESSED SIZE " + serializationService.toData(new Test()).totalSize());
}
{
SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
System.out.println("DEFAULT SIZE " + serializationService.toData(new Test()).totalSize());
}
}
Note that I am using a private API. This API should not be used on production.