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

feat(java): Add EnumNameSerializer for Enum #1791

Conversation

lionel-xie
Copy link

@lionel-xie lionel-xie commented Aug 5, 2024

What does this PR do?

Add EnumNameSerializer for Enum, can config it by org.apache.fury.config.Config#useEnumNameSerializer, default value is false

Related issues

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

java/fury-core/pom.xml Outdated Show resolved Hide resolved
@chaokunyang
Copy link
Collaborator

chaokunyang commented Aug 5, 2024

Hi @xxd819240366 , thanks for contribuing to Apache Fury. The code looks to me overall, I left some minor comments. And would you like to update org.apache.fury.serializer.NonexistentClassSerializers.NonexistentEnumClassSerializer in this PR?

java/pom.xml Outdated Show resolved Hide resolved
@lionel-xie
Copy link
Author

Ok,I'll update it again

@lionel-xie
Copy link
Author

By the way, I can pass all test on my local development environment with java 8,but can't pass test on Java CI(8) . There is a error in org.apache.fury.serializer.EnumSerializerTest.testEnumSubclassFieldCompatible(org.apache.fury.serializer.EnumSerializerTest) only happen on github CI pipline

@lionel-xie
Copy link
Author

@chaokunyang

@chaokunyang
Copy link
Collaborator

Seems some your jar version is 0.7.0 but others are 0.8.0-SNAPSHOT. Could you update all mavem module to 0.8.0-SNAPSHOT?

@lionel-xie
Copy link
Author

@chaokunyang Seems all maven module version already updated to 0.8.0-SNAPSHOT
1723965789422_paste_img

public Enum read(MemoryBuffer buffer) {
MetaStringBytes metaStringBytes = metaStringResolver.readMetaStringBytes(buffer);
if (!enumMap.containsKey(metaStringBytes)) {
Optional<NonexistentEnum> first = enumMap.values().stream().findFirst();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if deserializeNonexistentEnumValueAsNull is enabled, we should return null here, otherwise we should throw Exception

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or instead of returning null, we could return NonexistentEnum.UNKNOWN instead

Optional<NonexistentEnum> first = enumMap.values().stream().findFirst();
return first.orElse(null);
}
return enumMap.get(metaStringBytes);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduce a second map loopkup, we should avoid it. we can value = enumMap.get(xxx); and check whether value is null instead of check by containsKey

@chaokunyang
Copy link
Collaborator

image

@chaokunyang
Copy link
Collaborator

@lionel-xie Could you merge fury main branch first, your base branch is 0.7.0, not the developer main branch

@chaokunyang
Copy link
Collaborator

done in #1892

@chaokunyang chaokunyang closed this Nov 2, 2024
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

Successfully merging this pull request may close these issues.

2 participants