apache / fury

A blazingly fast multi-language serialization framework powered by JIT and zero-copy.
https://fury.apache.org/
Apache License 2.0
3.08k stars 246 forks source link

Enum equality does not work across serialization-deserialization #1644

Open Frnd-me opened 5 months ago

Frnd-me commented 5 months ago

Search before asking

Version

0.4.1

Component(s)

Java

Minimal reproduce step

public class EnumEquality {

  @Test
  public void testEnumEquality() throws URISyntaxException {
    final var fury = Fury.builder()
        .withLanguage(Language.XLANG)
        .requireClassRegistration(true)
        .build();

    fury.register(SomeEnum.class, "SomeEnum");

    final var someEnumOut = SomeEnum.A;

    final var someEnumIn = fury.deserialize(fury.serialize(someEnumOut));

    assertEquals(SomeEnum.A, someEnumIn);
  }

  public enum SomeEnum {
    A,
    B,
    C
  }
}

What did you expect to see?

I expect a test for equality of the original and deserialized enum values to result in a true value.

What did you see instead?

After deserializing, a test for equality of the deserialized enum value with the original value yields false.

Anything Else?

This must have something to do with Java's enums being singletons.

Are you willing to submit a PR?

Frnd-me commented 5 months ago

I am using the following as a workaround:

someEnumIn = SomeEnum.valueOf(someEnumIn.name());
chaokunyang commented 5 months ago

Hi @Frnd-me, could you use withLanguage(Language.JAVA) instead? Enum is not supported in xlang serialization for now., though fury serialization spec has included enum serialization protocol. Currently enum will be serialized as an struct, which is why deserialized value is not same reference

Frnd-me commented 5 months ago

I could try that, but that would imply that the cross-language serialization and deserialization would not work. I am trying to use Fury specifically for this feature.

chaokunyang commented 5 months ago

I could try that, but that would imply that the cross-language serialization and deserialization would not work. I am trying to use Fury specifically for this feature.

We're reactoring fury cross-language serialization. Could you hold this for some time? BTW, which languages you used fury for xlang serialization

Frnd-me commented 5 months ago

Sure, I will temporarily switch to Protocol Buffers, but I'll keep an eye on Fury. My system is implemented in Java, but would require cross-language serialization and deserialization from a range of other languages. I was currently testing Java <-> Python, but I can also see at least C++ and Go to be important languages for us.