Class Serialization
- java.lang.Object
-
- org.drasyl.pipeline.serialization.Serialization
-
public class Serialization extends Object
Holds aMap
with all availableSerializer
s and the classes each serializer should be used for. This class is used byMessageSerializer
to (de)serialize message objects when communicating with remote nodes.Each serializer is applied for objects of the assigned class, all subclasses, and all implementations.
Each received message includes the class name of the content. Normally, we would have to invoke the method
Class.forName(String)
to load the associated class to find a serializer for the class, any subclass, or implementation. However, this method invocation poses a security risk because we cannot control the class name received from the remote node. For this reason, when adding aSerializer
, the classpath is scanned in advance for subclasses and implementations. These results will then later used when a message should be deserialized. This approach allows us to load only classes with validSerializer
s.- See Also:
MessageSerializer
-
-
Field Summary
Fields Modifier and Type Field Description protected static NullSerializer
NULL_SERIALIZER
-
Constructor Summary
Constructors Constructor Description Serialization(Map<String,Serializer> serializers, Map<Class<?>,String> bindings)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSerializer(Class<?> clazz, Serializer serializer)
Adds aserializer
as serializer for objects of typeclazz
.static void
buildInheritanceGraph()
Rebuilds the inheritance graph, but keeps the old values.Serializer
findSerializerFor(String clazzName)
Returns the configuredSerializer
for the givenclazzName
.void
removeSerializer(Class<?> clazz)
Removes all serializers for objects of typeclazz
.void
removeSerializer(Serializer serializer)
Removes given serializer from
-
-
-
Field Detail
-
NULL_SERIALIZER
protected static final NullSerializer NULL_SERIALIZER
-
-
Method Detail
-
buildInheritanceGraph
public static void buildInheritanceGraph()
Rebuilds the inheritance graph, but keeps the old values.
-
findSerializerFor
public Serializer findSerializerFor(String clazzName)
Returns the configuredSerializer
for the givenclazzName
. The configuredSerializer
is used if the configured class `isAssignableFrom` from theclazz
, i.e. the configured class is a super class or implemented interface. In case of ambiguity it is primarily using the most specific configured class, and secondly the entry configured first.- Parameters:
clazzName
- name of class for which a serializer should be searched for- Returns:
- serializer for given clazz or
null
if nothing found
-
addSerializer
public void addSerializer(Class<?> clazz, Serializer serializer)
Adds aserializer
as serializer for objects of typeclazz
.- Parameters:
clazz
- class the serializer should be used forserializer
- the serializer
-
removeSerializer
public void removeSerializer(Class<?> clazz)
Removes all serializers for objects of typeclazz
.- Parameters:
clazz
- class the serializer should be removed for
-
removeSerializer
public void removeSerializer(Serializer serializer)
Removes given serializer from- Parameters:
serializer
- the serializer that should be removed
-
-