Package io.microsphere.io
Class Deserializers
- java.lang.Object
-
- io.microsphere.io.Deserializers
-
public class Deserializers extends java.lang.ObjectA utility class for managing and retrievingDeserializerinstances based on the deserialized type.This class allows registration and lookup of deserializers via SPI (Service Provider Interface), supporting priority-based resolution to determine the most or least specific deserializer available.
Example Usage
// Create an instance with the default class loader Deserializers deserializers = new Deserializers(); // Load deserializers via SPI deserializers.loadSPI(); // Retrieve the highest priority deserializer for a specific type Deserializer<MyType> deserializer = deserializers.getHighestPriority(MyType.class); // Deserialize an object using the retrieved deserializer MyType obj = deserializer.deserialize(data);- Since:
- 1.0.0
- Author:
- Mercy
-
-
Constructor Summary
Constructors Constructor Description Deserializers()Deserializers(java.lang.ClassLoader classLoader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> java.util.List<Deserializer<T>>get(java.lang.Class<?> deserializedType)Get all instances ofDeserializerby the specified deserialized type<T> Deserializer<T>getHighestPriority(java.lang.Class<?> deserializedType)Get the highest priority instance ofDeserializerby the specified deserialized type<T> Deserializer<T>getLowestPriority(java.lang.Class<?> deserializedType)Get the lowest priority instance ofDeserializerby the specified deserialized typeDeserializer<?>getMostCompatible(java.lang.Class<?> deserializedType)Get the most compatible instance ofDeserializerby the specified deserialized typevoidloadSPI()
-
-
-
Method Detail
-
loadSPI
public void loadSPI()
-
getMostCompatible
public Deserializer<?> getMostCompatible(java.lang.Class<?> deserializedType)
Get the most compatible instance ofDeserializerby the specified deserialized type- Parameters:
deserializedType- the type to be deserialized- Returns:
nullif not found
-
getHighestPriority
public <T> Deserializer<T> getHighestPriority(java.lang.Class<?> deserializedType)
Get the highest priority instance ofDeserializerby the specified deserialized type- Type Parameters:
T- the type to be serialized- Parameters:
deserializedType- the type to be deserialized- Returns:
nullif not found
-
getLowestPriority
public <T> Deserializer<T> getLowestPriority(java.lang.Class<?> deserializedType)
Get the lowest priority instance ofDeserializerby the specified deserialized type- Type Parameters:
T- the type to be serialized- Parameters:
deserializedType- the type to be deserialized- Returns:
nullif not found
-
get
@Nonnull public <T> java.util.List<Deserializer<T>> get(java.lang.Class<?> deserializedType)
Get all instances ofDeserializerby the specified deserialized type- Type Parameters:
T- the type to be serialized- Parameters:
deserializedType- the type to be deserialized- Returns:
- non-null
List
-
-