Serializers for unmodifiable Java collections.#260
Merged
Conversation
Added serializers for collections created via Collections.unmodifiable...() and Collections.empty...() methods.
| * | ||
| * @author <a href="mailto:alex@chermenin.ru">Alex Chermenin</a> | ||
| */ | ||
| public class UnmodifiableCollectionSerializer extends Serializer<Collection<?>> { |
Contributor
There was a problem hiding this comment.
these are all basically the same. Can we share the code? Something like:
public abstract class UnmodifiableJavaCollectionSerializer<T, U> extends Serializer<T> {
protected U getInner(T t);
protected T build(U u);
@Override
public Collection<?> read(Kryo kryo, Input input, Class<T> type) {
try {
U c = (U) kryo.readClassAndObject(input);
return build(c);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void write(Kryo kryo, Output output, T object) {
try {
U c = getInner(object);
kryo.writeClassAndObject(output, c);
} catch (RuntimeException e) {
// Don't eat and wrap RuntimeExceptions because the ObjectBuffer.write...
// handles SerializationException specifically (resizing the buffer)...
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}Then we can just implement the code to read the inner and wrap for each of them.
Also, could you possibly set your editor to 2 space indent, which is the style we use?
Contributor
Author
|
Great thought! Thanks for review. |
Serializers of unmodifiable Java collections was refactored. Deleted serializers for empty collections (Kryo has default serializators for it).
johnynek
pushed a commit
that referenced
this pull request
Oct 11, 2016
* Serializers for unmodifiable and empty collections. Added serializers for collections created via Collections.unmodifiable...() and Collections.empty...() methods. * Some refactoring. Serializers of unmodifiable Java collections was refactored. Deleted serializers for empty collections (Kryo has default serializators for it).
johnynek
added a commit
that referenced
this pull request
Oct 11, 2016
* Serializers for unmodifiable and empty collections. Added serializers for collections created via Collections.unmodifiable...() and Collections.empty...() methods. * Some refactoring. Serializers of unmodifiable Java collections was refactored. Deleted serializers for empty collections (Kryo has default serializators for it).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added serializers for collections created via
Collections.unmodifiable...() and Collections.empty...() methods.