'Serialising a String using Kryo giving wrong output
I am attempting to use Kryo to serialise and deserialise objects. This is working for complex types (like Optional and Option) but not simpler types like String. The issue looks to be on the serialisation side (deserialisation looks to be working fine). The serialisation code looks like:
private String serialize(T input) {
Output output = new Output(2, -1);
kryo.writeObjectOrNull(output, input, type);
output.close();
final var bytes = output.toBytes();
return new String(bytes);
}
where type is Class<T> (e.g. if T is String then type would be String.class). If I compare input.getBytes() to bytes I can see that all of the bytes in the byte[] are correct other than the last byte. This would result in an input of something like test144 and a serialised output of test14�.
I stepped through the code using an example of type String and can see that the output value is actually correct until this line is executed (looks to be doing some sort of Bitwise OR for whatever reason).
Unsure if this is something I am doing wrong or a bug in the library.
Thanks for any help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
