public static class Genson.Builder extends Object
withConverters(Converter...) or custom converter Factories
withConverterFactory(Factory).
This class combines the builder design pattern with template pattern providing handy
configuration and extensibility. All its public methods are intended to be used in the
builder "style" and its protected methods are part of the template. When you call
create() method, it will start assembling all the configuration and build all the
required components by using the protected methods. For example if you wish to use in your
projects a Builder that will always create some custom
BeanDescriptorProvider you have to
extend createBeanDescriptorProvider(), or imagine that you implemented some
Converters that you always want to register then override getDefaultConverters().| Constructor and Description |
|---|
Genson.Builder() |
| Modifier and Type | Method and Description |
|---|---|
Genson.Builder |
addAlias(String alias,
Class<?> forClass)
Alias used in serialized class metadata instead of the full class name.
|
protected void |
addDefaultContextualFactories(List<ContextualFactory<?>> factories) |
protected void |
addDefaultConverterFactories(List<Factory<? extends Converter<?>>> factories)
Override this method if you want to change the default converter factories.
|
protected void |
addDefaultDeserializerFactories(List<Factory<? extends Deserializer<?>>> deserializerFactories) |
protected void |
addDefaultSerializerFactories(List<Factory<? extends Serializer<?>>> serializerFactories) |
Genson |
create()
Creates an instance of Genson.
|
protected Genson |
create(Factory<Converter<?>> converterFactory,
Map<String,Class<?>> classAliases)
In theory this allows you to extend Genson class and to instantiate it, but actually you
can not do it as Genson class is final.
|
protected BeanDescriptorProvider |
createBeanDescriptorProvider()
Creates the standard BeanDescriptorProvider that will be used to provide
BeanDescriptor instances for
serialization/deserialization of all types that couldn't be handled by standard and
custom converters and converter factories. |
protected BeanMutatorAccessorResolver |
createBeanMutatorAccessorResolver() |
protected BeanPropertyFactory |
createBeanPropertyFactory() |
protected Factory<Converter<?>> |
createConverterFactory()
You should override this method if you want to add custom
ChainedFactory or if you need to chain
them differently. |
protected PropertyNameResolver |
createPropertyNameResolver()
You can override this method if you want to change the
PropertyNameResolver that are
registered by default. |
Genson.Builder |
exclude(Class<?> fieldOfType) |
Genson.Builder |
exclude(String field) |
Genson.Builder |
exclude(String field,
Class<?> fromClass) |
Genson.Builder |
exclude(String field,
Class<?> fromClass,
Class<?> ofType) |
protected BeanDescriptorProvider |
getBeanDescriptorProvider() |
protected BeanViewDescriptorProvider |
getBeanViewDescriptorProvider() |
VisibilityFilter |
getConstructorFilter() |
protected List<Converter<?>> |
getDefaultConverters()
You can override this methods if you want to change the default converters (remove some,
change the order, etc).
|
protected List<Deserializer<?>> |
getDefaultDeserializers() |
protected List<Serializer<?>> |
getDefaultSerializers() |
Map<Type,Deserializer<?>> |
getDeserializersMap() |
List<Factory<?>> |
getFactories() |
VisibilityFilter |
getFieldFilter() |
VisibilityFilter |
getMethodFilter() |
protected BeanMutatorAccessorResolver |
getMutatorAccessorResolver() |
Converter<Object> |
getNullConverter() |
protected PropertyNameResolver |
getPropertyNameResolver() |
Map<Type,Serializer<?>> |
getSerializersMap() |
Genson.Builder |
include(Class<?> fieldOfType) |
Genson.Builder |
include(String field) |
Genson.Builder |
include(String field,
Class<?> fromClass) |
Genson.Builder |
include(String field,
Class<?> fromClass,
Class<?> ofType) |
boolean |
isHtmlSafe() |
boolean |
isIndented() |
boolean |
isMetadata()
true if metadata is enabled during parsing.
|
boolean |
isSkipNull() |
boolean |
isStrictDoubleParse() |
boolean |
isThrowExceptionOnNoDebugInfo() |
boolean |
isUseFields() |
boolean |
isUseGettersAndSetters() |
boolean |
isUseRuntimeTypeForSerialization() |
boolean |
isWithBeanViewConverter() |
boolean |
isWithClassMetadata() |
boolean |
isWithDebugInfoPropertyNameResolver() |
Genson.Builder |
rename(Class<?> fieldOfType,
String toName)
Renames all fields of type fieldOfType to toName.
|
Genson.Builder |
rename(String field,
Class<?> fromClass,
String toName)
Renames all fields named field declared in class fromClass to toName.
|
Genson.Builder |
rename(String field,
Class<?> fromClass,
String toName,
Class<?> ofType)
Renames all fields named field, of type fieldOfType and declared in fromClass to toName.
|
Genson.Builder |
rename(String field,
String toName)
Renames all fields named field to toName.
|
Genson.Builder |
rename(String field,
String toName,
Class<?> fieldOfType)
Renames all fields named field and of type fieldOfType to toName.
|
Genson.Builder |
set(BeanMutatorAccessorResolver resolver)
Replaces default
BeanMutatorAccessorResolver by the specified one. |
Genson.Builder |
set(PropertyNameResolver resolver)
Replaces default
PropertyNameResolver by the specified one. |
Genson.Builder |
setConstructorFilter(VisibilityFilter constructorFilter) |
Genson.Builder |
setDateFormat(DateFormat dateFormat)
Specifies the data format that should be used for java.util.Date serialization and
deserialization.
|
Genson.Builder |
setFieldFilter(VisibilityFilter propertyFilter) |
Genson.Builder |
setHtmlSafe(boolean htmlSafe)
If true \,<,>,&,= characters will be replaced by ', <, >, &, =
|
Genson.Builder |
setMethodFilter(VisibilityFilter methodFilter) |
Genson.Builder |
setNullConverter(Converter<Object> nullConverter)
Sets the null converter that should be used to handle null object values.
|
Genson.Builder |
setSkipNull(boolean skipNull)
If true will not serialize null values
|
Genson.Builder |
setStrictDoubleParse(boolean strictDoubleParse) |
Genson.Builder |
setThrowExceptionIfNoDebugInfo(boolean throwExcOnNoDebugInfo)
Used in conjunction with
setWithDebugInfoPropertyNameResolver(boolean). |
Genson.Builder |
setUseFields(boolean useFields)
If true, fields will be used when no getter/setter is available, except if you specified
that no getter/setter should be used with
setUseGettersAndSetters(boolean), in
that case only fields will be used. |
Genson.Builder |
setUseGettersAndSetters(boolean useGettersAndSetters)
If true, getters and setters would be used during serialization/deserialization in favor
of fields.
|
Genson.Builder |
setUseRuntimeTypeForSerialization(boolean useRuntimeTypeForSerialization)
If true the concrete type of the serialized object will always be used.
|
Genson.Builder |
setWithBeanViewConverter(boolean withBeanViewConverter)
If true
BeanView mechanism will be enabled. |
Genson.Builder |
setWithClassMetadata(boolean withClassMetadata)
Indicates whether class metadata should be serialized and used during deserialization.
|
Genson.Builder |
setWithDebugInfoPropertyNameResolver(boolean withDebugInfoPropertyNameResolver)
If true constructor and method arguments name will be resolved from the generated debug
symbols during compilation.
|
Genson.Builder |
useByteAsInt(boolean enable) |
Genson.Builder |
useIndentation(boolean indent)
If true outputed json will be indented using two spaces, otherwise (by default) all is
printed on same line.
|
Genson.Builder |
useMetadata(boolean metadata) |
Genson.Builder |
useTimeInMillis(boolean timeInMillis) |
Genson.Builder |
with(BeanMutatorAccessorResolver... resolvers)
Register additional BeanMutatorAccessorResolver that will be used before the standard
ones.
|
Genson.Builder |
with(GensonBundle... bundles)
Register some genson bundles.
|
Genson.Builder |
with(PropertyNameResolver... resolvers)
Registers the specified resolvers in the order they were defined and before the standard
ones.
|
Genson.Builder |
withBeanPropertyFactory(BeanPropertyFactory... factories)
Allows you to register new BeanPropertyFactory responsible of creating BeanProperty
accessors, mutators and BeanCreators.
|
Genson.Builder |
withContextualFactory(ContextualFactory<?>... factories)
ContextualFactory is actually in a beta status, it will not be removed, but might be
refactored.
|
<T> Genson.Builder |
withConverter(Converter<T> converter,
Class<? extends T> type)
Register converter by mapping it to type argument.
|
<T> Genson.Builder |
withConverter(Converter<T> converter,
GenericType<? extends T> type)
Register converter by mapping it to the parameterized type of type argument.
|
Genson.Builder |
withConverterFactory(Factory<? extends Converter<?>> factory)
Registers converter factories.
|
Genson.Builder |
withConverters(Converter<?>... converter)
Registers converters mapping them to their corresponding parameterized type.
|
<T> Genson.Builder |
withDeserializer(Deserializer<T> deserializer,
Class<? extends T> type) |
<T> Genson.Builder |
withDeserializer(Deserializer<T> deserializer,
GenericType<? extends T> type) |
Genson.Builder |
withDeserializerFactory(Factory<? extends Deserializer<?>> factory)
Registers deserializer factories.
|
Genson.Builder |
withDeserializers(Deserializer<?>... deserializer) |
<T> Genson.Builder |
withSerializer(Serializer<T> serializer,
Class<? extends T> type) |
<T> Genson.Builder |
withSerializer(Serializer<T> serializer,
GenericType<? extends T> type) |
Genson.Builder |
withSerializerFactory(Factory<? extends Serializer<?>> factory)
Registers serializer factories.
|
Genson.Builder |
withSerializers(Serializer<?>... serializer) |
public Genson.Builder addAlias(String alias, Class<?> forClass)
ClassMetadataConverter for more
metadata. If you add an alias, it will automatically enable the class metadata feature,
as if you used setWithClassMetadata(boolean).alias - forClass - public Genson.Builder withConverters(Converter<?>... converter)
converter - public <T> Genson.Builder withConverter(Converter<T> converter, Class<? extends T> type)
converter - to registertype - of objects this converter handlespublic <T> Genson.Builder withConverter(Converter<T> converter, GenericType<? extends T> type)
converter - to registertype - of objects this converter handlespublic Genson.Builder withSerializers(Serializer<?>... serializer)
public <T> Genson.Builder withSerializer(Serializer<T> serializer, Class<? extends T> type)
public <T> Genson.Builder withSerializer(Serializer<T> serializer, GenericType<? extends T> type)
public Genson.Builder withDeserializers(Deserializer<?>... deserializer)
public <T> Genson.Builder withDeserializer(Deserializer<T> deserializer, Class<? extends T> type)
public <T> Genson.Builder withDeserializer(Deserializer<T> deserializer, GenericType<? extends T> type)
public Genson.Builder withConverterFactory(Factory<? extends Converter<?>> factory)
factory - to registerpublic Genson.Builder withSerializerFactory(Factory<? extends Serializer<?>> factory)
factory - to registerpublic Genson.Builder withDeserializerFactory(Factory<? extends Deserializer<?>> factory)
factory - to registerpublic Genson.Builder withContextualFactory(ContextualFactory<?>... factories)
public Genson.Builder withBeanPropertyFactory(BeanPropertyFactory... factories)
public Genson.Builder rename(String field, String toName)
public Genson.Builder rename(Class<?> fieldOfType, String toName)
public Genson.Builder rename(String field, Class<?> fromClass, String toName)
public Genson.Builder rename(String field, String toName, Class<?> fieldOfType)
public Genson.Builder rename(String field, Class<?> fromClass, String toName, Class<?> ofType)
public Genson.Builder exclude(String field)
public Genson.Builder exclude(Class<?> fieldOfType)
public Genson.Builder exclude(String field, Class<?> fromClass)
public Genson.Builder exclude(String field, Class<?> fromClass, Class<?> ofType)
public Genson.Builder include(String field)
public Genson.Builder include(Class<?> fieldOfType)
public Genson.Builder include(String field, Class<?> fromClass)
public Genson.Builder include(String field, Class<?> fromClass, Class<?> ofType)
public Genson.Builder setSkipNull(boolean skipNull)
skipNull - indicates whether null values should be serialized or not.public boolean isSkipNull()
public Genson.Builder setHtmlSafe(boolean htmlSafe)
htmlSafe - indicates whether serialized data should be html safe.public boolean isHtmlSafe()
public Genson.Builder set(BeanMutatorAccessorResolver resolver)
BeanMutatorAccessorResolver by the specified one.resolver - public Genson.Builder set(PropertyNameResolver resolver)
PropertyNameResolver by the specified one.resolver - public Genson.Builder with(BeanMutatorAccessorResolver... resolvers)
resolvers - public Genson.Builder with(PropertyNameResolver... resolvers)
resolvers - public boolean isWithClassMetadata()
public Genson.Builder setWithClassMetadata(boolean withClassMetadata)
withClassMetadata - ClassMetadataConverterpublic Genson.Builder setDateFormat(DateFormat dateFormat)
dateFormat - public boolean isThrowExceptionOnNoDebugInfo()
public Genson.Builder setThrowExceptionIfNoDebugInfo(boolean throwExcOnNoDebugInfo)
setWithDebugInfoPropertyNameResolver(boolean). If true
an exception will be thrown when a class has been compiled without debug informations.throwExcOnNoDebugInfo - ASMCreatorParameterNameResolverpublic boolean isUseGettersAndSetters()
public Genson.Builder setUseGettersAndSetters(boolean useGettersAndSetters)
setUseFields(boolean). By
default getters, setters and fields will be used.useGettersAndSetters - public boolean isUseFields()
public Genson.Builder setUseFields(boolean useFields)
setUseGettersAndSetters(boolean), in
that case only fields will be used. By default getters, setters and fields will be used.useFields - public boolean isWithBeanViewConverter()
public Genson.Builder setWithBeanViewConverter(boolean withBeanViewConverter)
BeanView mechanism will be enabled.withBeanViewConverter - public boolean isUseRuntimeTypeForSerialization()
public Genson.Builder setUseRuntimeTypeForSerialization(boolean useRuntimeTypeForSerialization)
useRuntimeTypeForSerialization - public boolean isWithDebugInfoPropertyNameResolver()
public Genson.Builder setWithDebugInfoPropertyNameResolver(boolean withDebugInfoPropertyNameResolver)
ASMCreatorParameterNameResolver.withDebugInfoPropertyNameResolver - setThrowExceptionIfNoDebugInfo(boolean)public Genson.Builder setNullConverter(Converter<Object> nullConverter)
nullConverter - public VisibilityFilter getFieldFilter()
public Genson.Builder setFieldFilter(VisibilityFilter propertyFilter)
public VisibilityFilter getMethodFilter()
public Genson.Builder setMethodFilter(VisibilityFilter methodFilter)
public VisibilityFilter getConstructorFilter()
public Genson.Builder setConstructorFilter(VisibilityFilter constructorFilter)
public Map<Type,Serializer<?>> getSerializersMap()
public Map<Type,Deserializer<?>> getDeserializersMap()
public boolean isStrictDoubleParse()
public Genson.Builder setStrictDoubleParse(boolean strictDoubleParse)
public boolean isIndented()
public Genson.Builder useIndentation(boolean indent)
public Genson.Builder useTimeInMillis(boolean timeInMillis)
public Genson.Builder with(GensonBundle... bundles)
builder.with(new JAXBExtension());
GensonBundlepublic Genson.Builder useMetadata(boolean metadata)
public boolean isMetadata()
public Genson.Builder useByteAsInt(boolean enable)
public Genson create()
protected Genson create(Factory<Converter<?>> converterFactory, Map<String,Class<?>> classAliases)
converterFactory - classAliases - protected Factory<Converter<?>> createConverterFactory()
ChainedFactory or if you need to chain
them differently.protected BeanMutatorAccessorResolver createBeanMutatorAccessorResolver()
protected PropertyNameResolver createPropertyNameResolver()
PropertyNameResolver that are
registered by default. You can also simply replace the default PropertyNameResolver by
setting another one with set(PropertyNameResolver).PropertyNameResolver.CompositePropertyNameResolver, otherwise you will not be
able to add others PropertyNameResolvers using
with(PropertyNameResolver...) method.protected List<Converter<?>> getDefaultConverters()
protected void addDefaultConverterFactories(List<Factory<? extends Converter<?>>> factories)
factories - list, is not null.protected void addDefaultContextualFactories(List<ContextualFactory<?>> factories)
protected List<Serializer<?>> getDefaultSerializers()
protected void addDefaultSerializerFactories(List<Factory<? extends Serializer<?>>> serializerFactories)
protected List<Deserializer<?>> getDefaultDeserializers()
protected void addDefaultDeserializerFactories(List<Factory<? extends Deserializer<?>>> deserializerFactories)
protected BeanDescriptorProvider createBeanDescriptorProvider()
BeanDescriptor instances for
serialization/deserialization of all types that couldn't be handled by standard and
custom converters and converter factories.protected BeanPropertyFactory createBeanPropertyFactory()
protected final PropertyNameResolver getPropertyNameResolver()
protected final BeanMutatorAccessorResolver getMutatorAccessorResolver()
protected final BeanDescriptorProvider getBeanDescriptorProvider()
protected final BeanViewDescriptorProvider getBeanViewDescriptorProvider()
Copyright © 2014. All Rights Reserved.