apache / fury

A blazingly fast multi-language serialization framework powered by JIT and zero-copy.

Home Page:https://fury.apache.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enum equality does not work across serialization-deserialization

Frnd-me opened this issue · comments

Search before asking

  • I had searched in the issues and found no similar issues.

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?

  • I'm willing to submit a PR!

I am using the following as a workaround:

someEnumIn = SomeEnum.valueOf(someEnumIn.name());

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

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.

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

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.