Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.57 - Round trip issues with JSON serialiser - NaN/Infinity and Collections.emptyList #332

Open
richard-smith-preservica opened this issue Mar 15, 2023 · 0 comments

Comments

@richard-smith-preservica
Copy link

richard-smith-preservica commented Mar 15, 2023

I guess this is two issues but they kind of go together. We are using FST to serialise method call requests/responses to AMQP. We're currently successfully using it in binary mode, but would like to be able to format messages as JSON so they're human readable and easier to interface with outside Java. There are two things which won't currently go through a serialise/deserialise and come back with the same object:

  • Attempting to deserialise Collections.emptyList throws a "private constructor" error. It looks like FSTCollectionSerializer:79
    > if ( AbstractList.class.isAssignableFrom(objectClass) && objectClass.getName().startsWith( "java.util.Arrays" ) ) { ...
    ... should include java.util.Collections in this check?

  • A list of numbers containing NaN or Infinity values comes back with those values as strings. This is especially problematic because this can violate the list item type declaration on the list and cause weird downstream failures. I.e.
    List list = deserialize(serialize(Arrays.asList(2, 3, Double.NaN, Double.Infinity))
    list will end up as [ 2, 3, "NaN". "Infinity" ], and then if I try to do arithmetic on it I'll get a casting exception.
    (this issue JSON encoding: if double is infinite classcast exception on decoding "Infinity" #260 is related, in the non-collection scenario)
    This is because JSON doesn't support writing NaN and Infinity constants, but perhaps a configuration option to allow writing it like that anyway for ease of round trip? EDIT: You can already do this if you assume the internals of the JsonConfiguration like:

    JsonFactory factory = jsonConfig.getCoderSpecific();
   factory.disable(JsonWriteFeature.WRITE_NAN_AS_STRINGS.mappedFeature());
  factory.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS.mappedFeature());

If it's intended that users can assume the coder specific config is a JsonFactory then this is ok

We are using 2.57 on Java 8

richard-smith-preservica added a commit to richard-smith-preservica/fast-serialization that referenced this issue Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant