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

Allow Kryo serializer registration #441

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ subprojects {
implementation 'com.google.guava:guava:31.1-jre'

implementation "org.reflections:reflections:${reflectionsVersion}"
implementation 'com.esotericsoftware.kryo:kryo5:5.3.0'
api 'com.esotericsoftware.kryo:kryo5:5.3.0'

implementation('commons-io:commons-io:2.11.0'){
exclude group: 'commons-logging', module: 'commons-logging'
Expand Down
18 changes: 16 additions & 2 deletions utils/src/main/java/com/nedap/archie/util/KryoUtil.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package com.nedap.archie.util;

import com.esotericsoftware.kryo.kryo5.Kryo;
import com.esotericsoftware.kryo.kryo5.Serializer;
import com.esotericsoftware.kryo.kryo5.util.Pool;

import java.util.HashMap;

/**
* Created by pieter.bos on 03/11/15.
*/
public class KryoUtil {

// Build pool with SoftReferences enabled (optional)
private static Pool<Kryo> pool;
private static final Pool<Kryo> pool;

@SuppressWarnings("rawtypes")
private static final HashMap<Class, Serializer> serializers = new HashMap<>();
Comment on lines +17 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@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.


static {
// Pool constructor arguments: thread safe, soft references, maximum capacity
pool = new Pool<Kryo>(true, false) {
protected Kryo create () {
protected Kryo create() {
Kryo kryo = new Kryo();

kryo.setRegistrationRequired(false);
kryo.setReferences(true);
kryo.setCopyReferences(true);

serializers.forEach(kryo::register);

return kryo;
}
};
Expand All @@ -29,4 +38,9 @@ protected Kryo create () {
public static Pool<Kryo> getPool() {
return pool;
}

@SuppressWarnings("rawtypes")
public static void addSerializer(Class clazz, Serializer serializer) {
serializers.put(clazz, serializer);
}
Comment on lines +42 to +45
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@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.

}