Package net.solarnetwork.codec
Class PropertySerializerRegistrar
java.lang.Object
net.solarnetwork.codec.PropertySerializerRegistrar
A registrar of
PropertySerializer implementations mapped to specific
object types or property names.
The configurable properties of this class are:
- propertySerializers
- A property name mapping to
PropertySerializerimplementations for serializing those properties with. - classSerializers
- A property type mapping to
PropertySerializerimplementations for serializing those properties with.
- Version:
- 1.0
- Author:
- matt
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionserializeProperty(String propertyName, Class<?> propertyType, Object bean, Object propertyValue) Attempt to serialize a property using a configuredPropertySerializer, returningpropertyValueif no matching serializer configured.serializerFor(String propertyName, Class<?> propertyType) Return a configuredPropertySerializerfor either a specific property name or property type.voidsetClassSerializers(Map<String, PropertySerializer> classSerializers) voidsetPropertySerializers(Map<String, PropertySerializer> propertySerializers)
-
Constructor Details
-
PropertySerializerRegistrar
public PropertySerializerRegistrar()
-
-
Method Details
-
serializerFor
Return a configuredPropertySerializerfor either a specific property name or property type.The
propertySerializersmappings are consulted first (using the passed inpropertyNamevalue), and if no match is found there theclassSerializersmappings are consulted (using the passed inpropertyTypevalue). If no match is found, null is returned.- Parameters:
propertyName- the name of the property to serializepropertyType- the type of property to serialize- Returns:
- configured PropertySerializer, or null if none found
-
serializeProperty
public Object serializeProperty(String propertyName, Class<?> propertyType, Object bean, Object propertyValue) Attempt to serialize a property using a configuredPropertySerializer, returningpropertyValueif no matching serializer configured.This method calls
serializerFor(String, Class), and if that returns aPropertySerializerthebean,propertyName, andpropertyValuewill be passed toPropertySerializer.serialize(Object, String, Object)and the result of that returned from this method.If no matching serializer is found,
propertyValueis returned unchanged.- Parameters:
propertyName- the name of the property being serializedpropertyType- the type of property being serializedbean- the object the property is being serialized frompropertyValue- the value of the property to serialize- Returns:
- serialized value
-
getPropertySerializers
- Returns:
- the propertySerializers
-
setPropertySerializers
- Parameters:
propertySerializers- the propertySerializers to set
-
getClassSerializers
- Returns:
- the classSerializers
-
setClassSerializers
- Parameters:
classSerializers- the classSerializers to set
-