public class JSONSerializerFactory extends com.streamscape.omf.serializer.AbstractSerializerFactory implements SerializerFactory
Title: Object Mediation Framework
Description: JSON Serializer Factory.
JSONSerializer
object serialization mechanism and it alias map.
All serializers use the alias map to define how a particular object is serialized in relationship to other objects
in the graph. For example how sub-objects within an encapsulating object or a collection (ie. HashMap or ArrayList)
are represented. JSONSerializer
uses the alias map to associate objects to JSON object tags. There are two
ways to instantiate the factory:
(i) A calling framework (such as the fabric runtime) uses a combination of init(AbstractOMFManager, ObjectMediationAliasManager)
and subsequent call to getInstance()
to initialize the factory with it's environment. If the factory is constructed
using this method, a global alias map may be passed to the factory by the calling framework. The fabric runtime uses this
mechanism to initialize it's factories with a global, shared map.
(ii) Alternatively users may create a factory singleton by calling getInstance()
directly. If the singleton
is constructed using this method an internal alias mapping object is dynamically created and managed by the factory.
It has a shared scope and is shared across all JSON serializer instances, but not other serializers.
Initialization of the singleton constructs (or accepts) an ObjectMediationAliasManager
object that is used
to hold mappings between classes and their short names. The serializer factory provides methods for aliasing JSON object
elements as well as constructing a variety of customizable JSON serializers. This factory also provides extension methods
that allow object elements to be omitted, set to defaults or processed in a specific way, such as escaped or compressed.
Serializers are thread-safe and when used within the context of the StreamScape Framework allow for dynamic transformation between
objects of different structures as well as different data formats such as XML, Binary, JSON notation or user defined object
representation. The alias definitions and format-specific serialization hints guarantee that a serialized object will properly
marshal and unmarshal to/from a given object as well as between formats. In this way the serialization mechanism also acts as
high-performance mapping and cross-language transformation tool.
Copyright: Copyright (c) 2010
Company: StreamScape Technologies
Modifier and Type | Class and Description |
---|---|
static interface |
JSONSerializerFactory.JsonSerializerFactoryBuilder |
static interface |
JSONSerializerFactory.JsonSerializerFactoryBuilderLazy |
DEFAULT_SERIAL_VERSION_ID
Modifier and Type | Method and Description |
---|---|
void |
alias(SemanticType stype)
Adds an alias for this
Semantic Type to the global map. |
void |
alias(java.lang.String alias,
java.lang.Class type)
Adds an alias for this class.
|
void |
aliasImmutableType(java.lang.Class type)
Adds an immutable class to the Alias Map.
|
void |
aliasImmutableType(SemanticType stype)
Adds an immutable class to the Alias Map.
|
static ObjectMapper |
createDefaultEmptyMapper() |
JSONSerializer |
createSerializer(java.lang.String name)
Creates an instance of a named Serializer and returns a reference to it.
|
Serializer |
createSerializer(java.lang.String name,
ObjectMediationAliasManager aliasMgr)
Creates an instance of a named Serializer, passing an
AliasManager
instance to it and returns a reference to it. |
JSONSerializerFactory.JsonSerializerFactoryBuilderLazy |
createSerializerDefaultBuilderLazy(java.lang.String name) |
void |
destroy()
Clears and removes all structures and references used by this
factory (but does not clear or remove the Alias Map).
|
void |
discardSerializer(java.lang.String name)
Removes a serializer from the factory registry and cleans up all associated structures.
|
ObjectMapper |
getDefaultEmptyMapper() |
JSONSerializer |
getDefaultSerializer()
Returns the default serializer registered for this factory.
|
static JSONSerializerFactory |
getInstance()
Returns a reference to the singleton instance of the factory.
|
java.lang.String |
getName()
Returns the name of the
Serializer Factory . |
boolean |
isAliased(java.lang.Class type)
Checks if the specified class is already aliased in the associated
AliasManager . |
boolean |
isAliased(java.lang.String alias)
Checks if the specified alias already exists in the associated
AliasManager . |
boolean |
isImmutableTypeAliased(java.lang.Class type)
Checks if the specified class is aliased as an immutable type.
|
java.util.List |
listAliases()
Returns a list of all aliases.
|
java.util.List |
listSerializers()
Returns a list of all serializers registered by this factory.
|
java.lang.String |
lookup(java.lang.Class clazz)
Returns the alias type name associated with the specified class.
|
java.lang.String |
lookup(java.lang.String typeName)
Returns the name of the class associated with the specified alias.
|
SemanticType |
lookupSemanticType(java.lang.String aliasName)
Returns a copy of the
SemanticType associated with the specified alias. |
JSONSerializer |
lookupSerializer(java.lang.String name)
Returns a reference to the named serializer instance.
|
java.lang.String |
resolveClass(java.lang.String className)
Resolves the name of this class to the alias type name.
|
void |
unalias(SemanticType type)
Remove an alias for this
Semantic Type from the global map. |
void |
unalias(java.lang.String alias)
Removes the aliased type from the Alias Map.
|
getContext, getContextType, hasContext
clone, getSerialVersionUID
public static JSONSerializerFactory getInstance()
Alias Manager
. This method will create a default system serializer
called sys$serializer. The default is set up for switching class loader references.
The method will attempt to register system aliases if they are not already present.
Subsequent calls to this method will return the singleton instance.public ObjectMapper getDefaultEmptyMapper()
public static ObjectMapper createDefaultEmptyMapper()
public JSONSerializerFactory.JsonSerializerFactoryBuilderLazy createSerializerDefaultBuilderLazy(java.lang.String name)
public JSONSerializer createSerializer(java.lang.String name)
SerializerFactory
createSerializer
in interface SerializerFactory
name
- the name of the serializer.public Serializer createSerializer(java.lang.String name, ObjectMediationAliasManager aliasMgr)
SerializerFactory
AliasManager
instance to it and returns a reference to it. Users may option to pass in a shared
alias manager into the method, in which case proper concurrent access protocols
should be used.createSerializer
in interface SerializerFactory
name
- the name of the serializer.aliasMgr
- the AliasManager
of the serializer.public JSONSerializer getDefaultSerializer()
getDefaultSerializer
in interface SerializerFactory
public JSONSerializer lookupSerializer(java.lang.String name)
SerializerFactory
lookupSerializer
in interface SerializerFactory
name
- the name of serializer to be looked up.null
if the specified serializer does not exist.public java.util.List listSerializers()
SerializerFactory
listSerializers
in interface SerializerFactory
public void discardSerializer(java.lang.String name) throws FactoryManagerException
SerializerFactory
Serializer.destroy()
method associated with the serializer to
free any resources. This method uses the name to lookup the serializer.discardSerializer
in interface SerializerFactory
name
- the name of serializer to be discarded.FactoryManagerException
- if the specified serializer does not exist.public void destroy()
SerializerFactory
destroy
in interface SerializerFactory
public void alias(SemanticType stype) throws FactoryManagerException
SerializerFactory
Semantic Type
to the global map.
AliasManager
interface to add system types and perform validation.
Note that this method does not require instantiation of a class. It is the preferred
way to create aliases.alias
in interface SerializerFactory
stype
- the semantic type to be aliased.FactoryManagerException
- if the specified type is already aliased.public void alias(java.lang.String alias, java.lang.Class type) throws FactoryManagerException
SerializerFactory
SemanticType
with an auto-generated serial version identifier.
It is intended for registering transient types that do not require
validation and is mainly retained for compatibility with older serialization mechanisms.alias
in interface SerializerFactory
alias
- the alias to be added.type
- the class to be aliased.FactoryManagerException
- if the specified alias already exists or
if the specified type is already aliased.public void aliasImmutableType(SemanticType stype) throws FactoryManagerException
SerializerFactory
java.lang.String
or collections.aliasImmutableType
in interface SerializerFactory
stype
- the semantic type to be aliased.FactoryManagerException
- if some error occurs.public void aliasImmutableType(java.lang.Class type)
SerializerFactory
java.lang.String
or collections.aliasImmutableType
in interface SerializerFactory
type
- the class to be aliased.public boolean isImmutableTypeAliased(java.lang.Class type)
SerializerFactory
isImmutableTypeAliased
in interface SerializerFactory
type
- the class to be checked.true
if the specified class is aliased as an immutable type, false
otherwise.public void unalias(SemanticType type) throws FactoryManagerException
SerializerFactory
Semantic Type
from the global map.
unalias
in interface SerializerFactory
type
- the semantic type to be unaliased.FactoryManagerException
- if the specified type is not aliased or
if the specified type is a system type.public void unalias(java.lang.String alias) throws FactoryManagerException
SerializerFactory
unalias
in interface SerializerFactory
alias
- the alias to be removed.FactoryManagerException
- if the specified alias does not exist or
if the specified type is a system type.public java.util.List listAliases()
SerializerFactory
listAliases
in interface SerializerFactory
public java.lang.String lookup(java.lang.Class clazz)
SerializerFactory
lookup
in interface SerializerFactory
clazz
- the specified class.null
if the class is not aliased.public java.lang.String lookup(java.lang.String typeName)
SerializerFactory
lookup
in interface SerializerFactory
typeName
- the specified alias.null
if this alias does not exist.public SemanticType lookupSemanticType(java.lang.String aliasName)
SerializerFactory
SemanticType
associated with the specified alias.lookupSemanticType
in interface SerializerFactory
aliasName
- the specified alias.null
if the alias does not exist.public java.lang.String resolveClass(java.lang.String className)
SerializerFactory
resolveClass
in interface SerializerFactory
className
- the specified class name.null
if the class is not aliased.public java.lang.String getName()
SerializerFactory
Serializer Factory
.getName
in interface SerializerFactory
public boolean isAliased(java.lang.String alias)
SerializerFactory
AliasManager
.isAliased
in interface SerializerFactory
alias
- the alias to be checked.true
if the specified alias already exists, false
otherwise.public boolean isAliased(java.lang.Class type)
SerializerFactory
AliasManager
.isAliased
in interface SerializerFactory
type
- the class to be checked.true
if the specified class is already aliased, false
otherwise.Copyright © 2015-2024 StreamScape Technologies. All rights reserved.