-
Notifications
You must be signed in to change notification settings - Fork 25
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
Allow Kryo serializer registration #441
Conversation
Codecov ReportBase: 71.34% // Head: 71.34% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #441 +/- ##
============================================
- Coverage 71.34% 71.34% -0.01%
Complexity 6723 6723
============================================
Files 657 657
Lines 22254 22258 +4
Branches 3573 3573
============================================
+ Hits 15877 15879 +2
- Misses 4680 4682 +2
Partials 1697 1697
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Another solution would be to add this line in kryo.addDefaultSerializer(URL.class, URLSerializer.class); See EsotericSoftware/kryo#885 (comment) But that would mean it applies to everyone using Archie 😛 (which maybe is a good thing?) |
I think registering the default serializer is a better solution. This Kryo instance is only intended for cloning, not for serializing and deserializing, so backwards compatibility should not be an issue. The benefit is that more of Archie just works in more cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think registering the default serializer is a better solution.
I agree. The current solution could also give strange behavior if the pool is already used before addSerializer
is called.
@SuppressWarnings("rawtypes") | ||
private static final HashMap<Class, Serializer> serializers = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SuppressWarnings("rawtypes") | |
private static final HashMap<Class, Serializer> serializers = new HashMap<>(); | |
private static final HashMap<Class<?>, Serializer<?>> serializers = new HashMap<>(); |
This fixes the warning without suppressing it.
@SuppressWarnings("rawtypes") | ||
public static void addSerializer(Class clazz, Serializer serializer) { | ||
serializers.put(clazz, serializer); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SuppressWarnings("rawtypes") | |
public static void addSerializer(Class clazz, Serializer serializer) { | |
serializers.put(clazz, serializer); | |
} | |
public static <T> void addSerializer(Class<T> clazz, Serializer<T> serializer) { | |
serializers.put(clazz, serializer); | |
} |
This fixes the warning without suppressing it.
Closing this for the alternative solution |
Need to discuss this solution.
This would allow implementing applications to use
KryoUtil.addSerializer(URI::class.java, URISerializer())
for example.Which solves this crash when attempting to clone anything with a
DV_MULTIMEDIA
on Android (wherejava.net.URI
can be from Java 8 which has no default empty constructor)Note: I grabbed a serializer to test this out from https://github.com/magro/kryo-serializers
Example from Android side (Kotlin)