fast-serialization icon indicating copy to clipboard operation
fast-serialization copied to clipboard

Add a new exception class to indicate "class X doesn't implement serializable."

Open jovany-wang opened this issue 3 years ago • 1 comments

https://github.com/RuedigerMoeller/fast-serialization/blob/master/src/main/java/org/nustaq/serialization/FSTClazzInfo.java#L143

We have a distributed exception handling system, which treats the distributed exceptions as local. For the following case:

  private static class UnSerializedClass {}

  private static class MyCustomException extends RuntimeException {
    private UnSerializedClass unSerializedClass = new UnSerializedClass();
  }

Our system may use FST to serialize MyCustomException and it's going fail because of the unserializable field UnSerializedClass . But our system shouldn't fail and should pack the stack messages as the serialized object. Now, our implementation like the following code:

byte[] serializedException;
try {
    serializedException = Fst.encode(exception);
} catch (RuntimeException e) {
    if (e.getMsg().contains("does not implement xxxx")) {
        serializedException = Fst.encode(Utils.getStackTrace(exception));
    } else {
        // xxx
    }
}

// send this `serializedException` bytes to the others.

So, it's necessary to have the new class SerializableNotImplementException(or other class name), to let user code clean:

byte[] serializedException;
try {
    serializedException = Fst.encode(exception);
} catch (SerializableNotImplementException e) {
    serializedException = Fst.encode(Utils.getStackTrace(exception));
}
// send this `serializedException` bytes to the others.

jovany-wang avatar Dec 28 '20 15:12 jovany-wang

@RuedigerMoeller

If it looks good to you, I'd like to post a PR for it.

jovany-wang avatar Dec 28 '20 16:12 jovany-wang