This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-fury.git
The following commit(s) were added to refs/heads/main by this push:
new 3dd67f9c feat(java): register old version guava collect (#1622)
3dd67f9c is described below
commit 3dd67f9cd511925b2d29e672531730d49859d1a0
Author: 李舒畅 <[email protected]>
AuthorDate: Fri May 10 21:24:04 2024 +0800
feat(java): register old version guava collect (#1622)
## What does this PR do?
<!-- Describe the purpose of this PR. -->
before guava 19.0, of() return
EmptyImmutableSet/EmptyImmutableBiMap/EmptyImmutableSortedMap/EmptyImmutableSortedSet.
check class and register serializer for them.
## Related issues
<!--
Is there any related issue? Please attach here.
- #xxxx0
- #xxxx1
- #xxxx2
-->
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/incubator-fury/issues/new/choose)
describing the need to do so and update the document if necessary.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->
---
.../collection/GuavaCollectionSerializers.java | 57 ++++++++++++++++++++--
1 file changed, 54 insertions(+), 3 deletions(-)
diff --git
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/GuavaCollectionSerializers.java
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/GuavaCollectionSerializers.java
index b05b378c..44aa025d 100644
---
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/GuavaCollectionSerializers.java
+++
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/GuavaCollectionSerializers.java
@@ -373,6 +373,7 @@ public class GuavaCollectionSerializers {
// guava/TreeMultimapSerializer - serializer for guava-libraries'
TreeMultimap
// guava/UnmodifiableNavigableSetSerializer - serializer for guava-libraries'
// UnmodifiableNavigableSet
+
public static void registerDefaultSerializers(Fury fury) {
// Note: Guava common types are not public API, don't register by
`ImmutableXXX.of()`,
// since different guava version may return different type objects, which
make class
@@ -380,17 +381,18 @@ public class GuavaCollectionSerializers {
// inconsistent if peers load different version of guava.
// For example: guava 20 return ImmutableBiMap for ImmutableMap.of(), but
guava 27 return
// ImmutableMap.
- Class cls = loadClass(pkg + ".RegularImmutableBiMap",
ImmutableBiMap.of().getClass());
+ Class cls =
+ loadClass(pkg + ".RegularImmutableBiMap", ImmutableBiMap.of("k1", 1,
"k2", 4).getClass());
fury.registerSerializer(cls, new ImmutableBiMapSerializer(fury, cls));
cls = loadClass(pkg + ".SingletonImmutableBiMap", ImmutableBiMap.of(1,
2).getClass());
fury.registerSerializer(cls, new ImmutableBiMapSerializer(fury, cls));
- cls = loadClass(pkg + ".RegularImmutableMap",
ImmutableMap.of().getClass());
+ cls = loadClass(pkg + ".RegularImmutableMap", ImmutableMap.of("k1", 1,
"k2", 2).getClass());
fury.registerSerializer(cls, new ImmutableMapSerializer(fury, cls));
cls = loadClass(pkg + ".RegularImmutableList",
ImmutableList.of().getClass());
fury.registerSerializer(cls, new RegularImmutableListSerializer(fury,
cls));
cls = loadClass(pkg + ".SingletonImmutableList",
ImmutableList.of(1).getClass());
fury.registerSerializer(cls, new ImmutableListSerializer(fury, cls));
- cls = loadClass(pkg + ".RegularImmutableSet",
ImmutableSet.of().getClass());
+ cls = loadClass(pkg + ".RegularImmutableSet", ImmutableSet.of(1,
2).getClass());
fury.registerSerializer(cls, new ImmutableSetSerializer(fury, cls));
cls = loadClass(pkg + ".SingletonImmutableSet",
ImmutableSet.of(1).getClass());
fury.registerSerializer(cls, new ImmutableSetSerializer(fury, cls));
@@ -399,6 +401,46 @@ public class GuavaCollectionSerializers {
fury.registerSerializer(cls, new ImmutableSortedSetSerializer<>(fury,
cls));
cls = loadClass(pkg + ".ImmutableSortedMap", ImmutableSortedMap.of(1,
2).getClass());
fury.registerSerializer(cls, new ImmutableSortedMapSerializer<>(fury,
cls));
+
+ // Guava version before 19.0, of() return
+ //
EmptyImmutableSet/EmptyImmutableBiMap/EmptyImmutableSortedMap/EmptyImmutableSortedSet
+ // we register if class exist or register empty to deserialize.
+ if (checkClassExist(pkg + ".EmptyImmutableSet")) {
+ cls = loadClass(pkg + ".EmptyImmutableSet",
ImmutableSet.of().getClass());
+ fury.registerSerializer(cls, new ImmutableSetSerializer(fury, cls));
+ } else {
+ class GuavaEmptySet {}
+
+ cls = GuavaEmptySet.class;
+ fury.registerSerializer(cls, new ImmutableSetSerializer(fury, cls));
+ }
+ if (checkClassExist(pkg + ".EmptyImmutableBiMap")) {
+ cls = loadClass(pkg + ".EmptyImmutableBiMap",
ImmutableBiMap.of().getClass());
+ fury.registerSerializer(cls, new ImmutableMapSerializer(fury, cls));
+ } else {
+ class GuavaEmptyBiMap {}
+
+ cls = GuavaEmptyBiMap.class;
+ fury.registerSerializer(cls, new ImmutableMapSerializer(fury, cls));
+ }
+ if (checkClassExist(pkg + ".EmptyImmutableSortedSet")) {
+ cls = loadClass(pkg + ".EmptyImmutableSortedSet",
ImmutableSortedSet.of().getClass());
+ fury.registerSerializer(cls, new ImmutableSortedSetSerializer(fury,
cls));
+ } else {
+ class GuavaEmptySortedSet {}
+
+ cls = GuavaEmptySortedSet.class;
+ fury.registerSerializer(cls, new ImmutableSortedSetSerializer(fury,
cls));
+ }
+ if (checkClassExist(pkg + ".EmptyImmutableSortedMap")) {
+ cls = loadClass(pkg + ".EmptyImmutableSortedMap",
ImmutableSortedMap.of().getClass());
+ fury.registerSerializer(cls, new ImmutableSortedMapSerializer(fury,
cls));
+ } else {
+ class GuavaEmptySortedMap {}
+
+ cls = GuavaEmptySortedMap.class;
+ fury.registerSerializer(cls, new ImmutableSortedMapSerializer(fury,
cls));
+ }
}
static Class<?> loadClass(String className, Class<?> cache) {
@@ -412,4 +454,13 @@ public class GuavaCollectionSerializers {
}
}
}
+
+ static boolean checkClassExist(String className) {
+ try {
+ Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ return true;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]