elementType = kryo.readClass(input).getType();
+ final EnumSet result = EnumSet.noneOf(elementType);
+ final int size = input.readInt(true);
+ final Enum>[] enumConstants = elementType.getEnumConstants();
+ for (int i = 0; i < size; i++) {
+ result.add(enumConstants[input.readInt(true)]);
+ }
+ return result;
+ }
- @Override
- public void write(final Kryo kryo, final Output output, final EnumSet extends Enum>> set) {
- kryo.writeClass( output, getElementType( set ) );
- output.writeInt( set.size(), true );
- for (final Enum item : set) {
- output.writeInt(item.ordinal(), true);
- }
+ @Override
+ public void write(final Kryo kryo, final Output output, final EnumSet extends Enum>> set) {
+ kryo.writeClass(output, getElementType(set));
+ output.writeInt(set.size(), true);
+ for (final Enum item : set) {
+ output.writeInt(item.ordinal(), true);
+ }
- if ( TRACE ) trace( "kryo", "Wrote EnumSet: " + set );
- }
+ if (TRACE)
+ trace("kryo", "Wrote EnumSet: " + set);
+ }
- private Class extends Enum>> getElementType( final EnumSet extends Enum>> set ) {
- try {
- return (Class)TYPE_FIELD.get( set );
- } catch ( final Exception e ) {
- throw new RuntimeException( "Could not access keys field.", e );
- }
- }
+ private Class extends Enum>> getElementType(final EnumSet extends Enum>> set) {
+ try {
+ return (Class) TYPE_FIELD.get(set);
+ } catch (final Exception e) {
+ throw new RuntimeException("Could not access keys field.", e);
+ }
+ }
}
diff --git a/src/main/java/de/javakaffee/kryoserializers/FieldAnnotationAwareSerializer.java b/src/main/java/de/javakaffee/kryoserializers/FieldAnnotationAwareSerializer.java
index c7373fcc..2f5a62fa 100644
--- a/src/main/java/de/javakaffee/kryoserializers/FieldAnnotationAwareSerializer.java
+++ b/src/main/java/de/javakaffee/kryoserializers/FieldAnnotationAwareSerializer.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Martin Grotzke
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
package de.javakaffee.kryoserializers;
import static com.esotericsoftware.minlog.Log.TRACE;
@@ -18,7 +34,6 @@
* A kryo {@link FieldSerializer} that allows to exclusively include or exclude fields that
* are attributed with user-specific annotations. This can be for example useful when serializing beans that carry
* references to a dependency injection framework. As an example for Spring:
- *
*
* {@code
* Set> marks = new HashSet<>();
@@ -28,10 +43,10 @@
* kryo.setDefaultSerializer(factory);
* }
*
- *
+ *
* The resulting {@link Kryo} instance would ignore all fields that are annotated with Spring's {@code @Autowired}
* annotation.
- *
+ *
* Similarly, it is possible to created a serializer which does the opposite such that the resulting serializer
* would only serialize fields that are annotated with the specified annotations.
*
@@ -40,150 +55,148 @@
*/
public class FieldAnnotationAwareSerializer extends FieldSerializer {
- /**
- * A factory for creating instances of {@link FieldAnnotationAwareSerializer}.
- */
- public static class Factory implements SerializerFactory {
-
- private final Collection> marked;
- private final boolean disregarding;
-
- /**
- * Creates a new factory. See {@link FieldAnnotationAwareSerializer#FieldAnnotationAwareSerializer(
- *com.esotericsoftware.kryo.Kryo, Class, java.util.Collection, boolean)}
- * for additional information on the constructor parameters.
- *
- * @param marked The annotations that will be considered of the resulting converter.
- * @param disregarding If {@code true}, the serializer will ignore all annotated fields,
- * if set to {@code false} it will exclusively look at annotated fields.
- */
- public Factory(final Collection> marked, final boolean disregarding) {
- this.marked = marked;
- this.disregarding = disregarding;
- }
-
- @Override
- public Serializer> makeSerializer(final Kryo kryo, final Class> type) {
- return new FieldAnnotationAwareSerializer