Class PropertySerializerRegistrar

java.lang.Object
net.solarnetwork.codec.PropertySerializerRegistrar

public class PropertySerializerRegistrar extends Object
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 PropertySerializer implementations for serializing those properties with.
classSerializers
A property type mapping to PropertySerializer implementations for serializing those properties with.
Version:
1.0
Author:
matt
  • Constructor Details

    • PropertySerializerRegistrar

      public PropertySerializerRegistrar()
  • Method Details

    • serializerFor

      public PropertySerializer serializerFor(String propertyName, Class<?> propertyType)
      Return a configured PropertySerializer for either a specific property name or property type.

      The propertySerializers mappings are consulted first (using the passed in propertyName value), and if no match is found there the classSerializers mappings are consulted (using the passed in propertyType value). If no match is found, null is returned.

      Parameters:
      propertyName - the name of the property to serialize
      propertyType - 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 configured PropertySerializer, returning propertyValue if no matching serializer configured.

      This method calls serializerFor(String, Class), and if that returns a PropertySerializer the bean, propertyName, and propertyValue will be passed to PropertySerializer.serialize(Object, String, Object) and the result of that returned from this method.

      If no matching serializer is found, propertyValue is returned unchanged.

      Parameters:
      propertyName - the name of the property being serialized
      propertyType - the type of property being serialized
      bean - the object the property is being serialized from
      propertyValue - the value of the property to serialize
      Returns:
      serialized value
    • getPropertySerializers

      public Map<String,PropertySerializer> getPropertySerializers()
      Returns:
      the propertySerializers
    • setPropertySerializers

      public void setPropertySerializers(Map<String,PropertySerializer> propertySerializers)
      Parameters:
      propertySerializers - the propertySerializers to set
    • getClassSerializers

      public Map<String,PropertySerializer> getClassSerializers()
      Returns:
      the classSerializers
    • setClassSerializers

      public void setClassSerializers(Map<String,PropertySerializer> classSerializers)
      Parameters:
      classSerializers - the classSerializers to set