Class SerializerBuilder
- All Implemented Interfaces:
WithInitializer<SerializerBuilder>
-
Method Summary
Modifier and TypeMethodDescription<T> BinarySerializer<T>build(SerializerDef serializer) Builds aBinarySerializerout of someSerializerDef.<T> BinarySerializer<T>build(io.activej.types.TypeT<T> typeT) <T> BinarySerializer<T><T> BinarySerializer<T>build(AnnotatedType type) <T> BinarySerializer<T><T> BinarySerializer<T><T> BinarySerializer<T><T> BinarySerializer<T>build(String className, AnnotatedType type) <T> BinarySerializer<T>static SerializerBuildercreate()Creates a new instance ofSerializerBuilderwith newly createdDefiningClassLoaderstatic SerializerBuildercreate(DefiningClassLoader definingClassLoader) Creates a new instance ofSerializerBuilderwith externalDefiningClassLoader<T> ClassBuilder<BinarySerializer<T>>toClassBuilder(SerializerDef serializer) with(io.activej.types.TypeT<?> typeT, io.activej.types.scanner.TypeScannerRegistry.Mapping<SerializerDef> fn) Adds a mapping to resolve aSerializerDeffor a givenTypeTwith(Type type, io.activej.types.scanner.TypeScannerRegistry.Mapping<SerializerDef> fn) Adds a mapping to resolve aSerializerDeffor a givenType<A extends Annotation,T extends Annotation>
SerializerBuilderwithAnnotationAlias(Class<A> annotation, Class<T> annotationAlias, Function<T, A> mapping) Adds alias annotation for a serializer annotation.Enables annotation compatibility modewithAnnotationCompatibilityMode(boolean annotationsCompatibilityMode) Enables or disables annotation compatibility modewithAutoOrdering(int autoOrderingStart, int autoOrderingStride) Sets auto ordering parameters (used when no explicit ordering is set)withCompatibilityLevel(CompatibilityLevel compatibilityLevel) Sets a givenCompatibilityLevelfor the serializer.withDecodeVersions(int decodeVersionMin, int decodeVersionMax) Sets both minimal and maximal decode versionswithEncodeVersion(int encodeVersionMax) Sets maximal encode versionwithImplementationClass(Class<?> implementationClass) Adds an implementation class for the serializerwithProfile(String profile) Sets a serializer profilewithSubclasses(Class<T> type, List<Class<? extends T>> subclasses) Sets subclasses to be serialized.withSubclasses(String subclassesId, List<Class<? extends T>> subclasses) Sets subclasses to be serialized.withVersions(int encodeVersionMax, int decodeVersionMin, int decodeVersionMax) Sets maximal encode version as well as both minimal and maximal decode versionsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.activej.codegen.util.WithInitializer
withInitializer, withInitializer
-
Method Details
-
create
Creates a new instance ofSerializerBuilderwith newly createdDefiningClassLoader -
create
Creates a new instance ofSerializerBuilderwith externalDefiningClassLoader -
with
public SerializerBuilder with(io.activej.types.TypeT<?> typeT, io.activej.types.scanner.TypeScannerRegistry.Mapping<SerializerDef> fn) Adds a mapping to resolve aSerializerDeffor a givenTypeT- Parameters:
typeT- a type tokenfn- a mapping to resolve a serializer
-
with
public SerializerBuilder with(Type type, io.activej.types.scanner.TypeScannerRegistry.Mapping<SerializerDef> fn) Adds a mapping to resolve aSerializerDeffor a givenType- Parameters:
type- a typefn- a mapping to resolve a serializer
-
withImplementationClass
Adds an implementation class for the serializer- Parameters:
implementationClass- an implementation class
-
withCompatibilityLevel
Sets a givenCompatibilityLevelfor the serializer. This method should be used to ensure backwards compatibility with previous versions of serializers- Parameters:
compatibilityLevel- a compatibility level
-
withAnnotationCompatibilityMode
Enables annotation compatibility mode- See Also:
-
withAnnotationCompatibilityMode
Enables or disables annotation compatibility modeIn previous ActiveJ versions serializer annotations had to be placed directly on fields/getters. To specify a concrete annotated type a
pathattribute was used. Now it is possible to annotate types directly. However, for compatibility with classes annotated using apathattribute or when using older versions of Java that may fail resolving type use annotations, this compatibility mode can be enabled -
withAnnotationAlias
public <A extends Annotation,T extends Annotation> SerializerBuilder withAnnotationAlias(Class<A> annotation, Class<T> annotationAlias, Function<T, A> mapping) Adds alias annotation for a serializer annotation. Alias annotation acts as if it is a regular serializer annotation- Type Parameters:
A- a type of serializer annotationT- a type of alias annotation- Parameters:
annotation- a serializer annotationannotationAlias- an alias annotationmapping- a function that transforms an alias annotation into a serializer annotation
-
withEncodeVersion
Sets maximal encode versionThis method is used to ensure compatibility between different versions of serialized objects
- Parameters:
encodeVersionMax- a maximal encode version
-
withDecodeVersions
Sets both minimal and maximal decode versionsThis method is used to ensure compatibility between different versions of serialized objects
- Parameters:
decodeVersionMin- a minimal decode versiondecodeVersionMax- a maximal decode version
-
withVersions
public SerializerBuilder withVersions(int encodeVersionMax, int decodeVersionMin, int decodeVersionMax) Sets maximal encode version as well as both minimal and maximal decode versionsThis method is used to ensure compatibility between different versions of serialized objects
- Parameters:
encodeVersionMax- a maximal encode versiondecodeVersionMin- a minimal decode versiondecodeVersionMax- a maximal decode version
-
withAutoOrdering
Sets auto ordering parameters (used when no explicit ordering is set)- Parameters:
autoOrderingStart- a value of initial order indexautoOrderingStride- a step between indices
-
withProfile
Sets a serializer profile- Parameters:
profile- a serializer profile
-
withSubclasses
public <T> SerializerBuilder withSubclasses(String subclassesId, List<Class<? extends T>> subclasses) Sets subclasses to be serialized. Uses custom string id to identify subclasses- Type Parameters:
T- a parent of subclasses- Parameters:
subclassesId- an id of subclassessubclasses- actual subclasses classes
-
withSubclasses
Sets subclasses to be serialized. Uses parent class to identify subclasses- Type Parameters:
T- a parent type of subclasses- Parameters:
type- a parent class of subclassessubclasses- actual subclasses classes
-
build
- See Also:
-
build
- See Also:
-
build
- See Also:
-
build
- Parameters:
type- a type data that would be serialized- Returns:
- a generated
BinarySerializer
-
build
- See Also:
-
build
- See Also:
-
build
- See Also:
-
build
Builds aBinarySerializerout ofthisSerializerBuilder.A built serializer would have a class name equal to the one that passed to this method.
If
classLoaderhas already defined the serializer class, the class would be taken from the class loader's cache. Moreover, if aDefiningClassLoaderhas a persistentBytecodeStorage, the serializer class would be taken from that persistent cache.- Parameters:
className- a name of the class of a serializertype- a type data that would be serialized- Returns:
- a generated
BinarySerializer
-
build
Builds aBinarySerializerout of someSerializerDef.- Parameters:
serializer- aSerializerDefthat would be used to create aBinarySerializer- Returns:
- a generated
BinarySerializer
-
toClassBuilder
- Type Parameters:
T- a type of data to be serialized by aBinarySerializer- Parameters:
serializer- a serializer definition- Returns:
- a
ClassBuilderofBinarySerializer
-