org.omnaest.utils.beans.mapconverter
Class BeanToNestedMapConverter<B>

java.lang.Object
  extended by org.omnaest.utils.beans.mapconverter.BeanToNestedMapConverter<B>

public class BeanToNestedMapConverter<B>
extends Object

A BeanToNestedMapConverter marshalls a given JavaBean into a Map or unmarshalls a given Map into a JavaBean. This process is transitive and allows to translate arbitrary object graphs into nested Maps.

With #newBeanPropertyAccessorWithPropertyAccessType(PropertyAccessType) it can be declared in which way the BeanToNestedMapConverter should access given JavaBeans. With the default value of BeanPropertyAccessor.PropertyAccessType.PROPERTY the BeanToNestedMapConverter will only use getters and setters whereby with BeanPropertyAccessor.PropertyAccessType.FIELD the fields of the JavaBeans are accessed directly ignoring any getters or setters.

Author:
Omnaest

Nested Class Summary
static interface BeanToNestedMapConverter.BeanConversionFilter
          A BeanToNestedMapConverter.BeanConversionFilter will decide which JavaBean should be converted into a Map and which should be put directly into the Map as Object
static class BeanToNestedMapConverter.BeanConversionFilterExcludingDeclaringJavaBaseClass
          Excludes all object instances which are assigned to a declared class which is an type from the "java.*" package space
static class BeanToNestedMapConverter.BeanConversionFilterExcludingJavaBaseClass
          Excludes all object instances which are an instance from the "java.*" package space
static class BeanToNestedMapConverter.BeanConversionFilterExcludingPrimitiveAndString
          Excludes all object instances which are primitives, wrappers for primitives or String
 
Constructor Summary
BeanToNestedMapConverter(BeanToNestedMapConverter.BeanConversionFilter beanConversionFilter, Class<? extends B> beanClass)
           
BeanToNestedMapConverter(BeanToNestedMapConverter.BeanConversionFilter beanConversionFilter, Class<? extends B> beanClass, BeanPropertyAccessor.PropertyAccessType propertyAccessType)
           
BeanToNestedMapConverter(BeanToNestedMapConverter.BeanConversionFilter beanConversionFilter, Class<? extends B> beanClass, BeanPropertyAccessor.PropertyAccessType propertyAccessType, Map<Class<?>,Class<?>> sourceTypeTodestinationTypeMap)
           
BeanToNestedMapConverter(BeanToNestedMapConverter.BeanConversionFilter beanConversionFilter, Class<? extends B> beanClass, Map<Class<?>,Class<?>> sourceTypeTodestinationTypeMap)
           
BeanToNestedMapConverter(Class<? extends B> beanClass)
           
 
Method Summary
 B clone(B bean)
          Clones a given bean by using marshal(Object) and using unmarshal(Map) again.
 Map<String,Object> marshal(B bean)
          Marshalls a given JavaBean into a nested Map
 B unmarshal(Map<String,Object> map)
          Unmarshalls a given nested Map in the respective JavaBean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanToNestedMapConverter

public BeanToNestedMapConverter(Class<? extends B> beanClass)
Parameters:
beanClass -

BeanToNestedMapConverter

public BeanToNestedMapConverter(BeanToNestedMapConverter.BeanConversionFilter beanConversionFilter,
                                Class<? extends B> beanClass)
Parameters:
beanConversionFilter -
beanClass -
propertyAccessType -
sourceTypeTodestinationTypeMap -
See Also:
BeanToNestedMapConverter

BeanToNestedMapConverter

public BeanToNestedMapConverter(BeanToNestedMapConverter.BeanConversionFilter beanConversionFilter,
                                Class<? extends B> beanClass,
                                BeanPropertyAccessor.PropertyAccessType propertyAccessType)
Parameters:
beanConversionFilter -
beanClass -
propertyAccessType -
See Also:
BeanToNestedMapConverter

BeanToNestedMapConverter

public BeanToNestedMapConverter(BeanToNestedMapConverter.BeanConversionFilter beanConversionFilter,
                                Class<? extends B> beanClass,
                                Map<Class<?>,Class<?>> sourceTypeTodestinationTypeMap)
Parameters:
beanConversionFilter -
beanClass -
sourceTypeTodestinationTypeMap -
See Also:
BeanToNestedMapConverter

BeanToNestedMapConverter

public BeanToNestedMapConverter(BeanToNestedMapConverter.BeanConversionFilter beanConversionFilter,
                                Class<? extends B> beanClass,
                                BeanPropertyAccessor.PropertyAccessType propertyAccessType,
                                Map<Class<?>,Class<?>> sourceTypeTodestinationTypeMap)
Parameters:
beanConversionFilter -
beanClass -
propertyAccessType -
sourceTypeTodestinationTypeMap -
See Also:
BeanToNestedMapConverter
Method Detail

marshal

public Map<String,Object> marshal(B bean)
Marshalls a given JavaBean into a nested Map

Parameters:
bean -
Returns:

unmarshal

public B unmarshal(Map<String,Object> map)
Unmarshalls a given nested Map in the respective JavaBean

Parameters:
map -
Returns:

clone

public B clone(B bean)
Clones a given bean by using marshal(Object) and using unmarshal(Map) again.

Parameters:
bean -
Returns:


Copyright © 2013. All Rights Reserved.