Package org.refcodes.net
Class JsonMediaTypeFactory
- java.lang.Object
-
- org.refcodes.net.JsonMediaTypeFactory
-
- All Implemented Interfaces:
Marshalable<java.lang.String>
,MediaTypeFactory
,MediaTypesAccessor
,Unmarshalable<java.lang.String>
- Direct Known Subclasses:
XmlMediaTypeFactory
public class JsonMediaTypeFactory extends java.lang.Object implements MediaTypeFactory
Implements theMediaTypeFactory
for Media-Type "application/json" (MediaType.APPLICATION_JSON
). CAUTION: This implementation uses field resolution instead of getter/setter property resolution as of the used marshaling API.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.net.MediaTypesAccessor
MediaTypesAccessor.MediaTypesBuilder<B extends MediaTypesAccessor.MediaTypesBuilder<B>>, MediaTypesAccessor.MediaTypesMutator, MediaTypesAccessor.MediaTypesProperty
-
-
Constructor Summary
Constructors Constructor Description JsonMediaTypeFactory()
Instantiates a new application JSON factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MediaType[]
getMediaTypes()
Retrieves the Media-Types from the Media-Types property.protected java.lang.String
toElementName(java.lang.Class<?> aClass)
Creates an element name for the class.java.lang.String
toMarshaled(java.lang.Object aObject)
This method creates / retrieves an instance of the given type with the given identifier (name) constructed as defined in one to many configuration files.protected java.lang.String
toPlainJson(java.lang.String aJson)
Removes any prefixed variable declaration.protected java.lang.String
toUnboxed(java.lang.String aJson)
Unboxes any enveloped JSON.<T> T
toUnmarshaled(java.lang.String aHttpBody, java.lang.Class<T> aType)
This method creates / retrieves an instance of the given type from the provided instance.protected java.lang.String
toVariableDeclaration(java.lang.Class<?> aClass)
Returns the JSON specific assignment declaration for the given class.-
Methods inherited from interface org.refcodes.net.Marshalable
toMarshaled
-
Methods inherited from interface org.refcodes.net.MediaTypeFactory
fromMarshaled, fromMarshaled, fromMarshaled, fromMarshaled, fromUnmarshaled, fromUnmarshaled
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.net.Unmarshalable
toUnmarshaled, toUnmarshaled, toUnmarshaled
-
-
-
-
Method Detail
-
getMediaTypes
public MediaType[] getMediaTypes()
Retrieves the Media-Types from the Media-Types property.- Specified by:
getMediaTypes
in interfaceMediaTypesAccessor
- Returns:
- The Media-Types stored by the Media-Types property.
-
toMarshaled
public java.lang.String toMarshaled(java.lang.Object aObject) throws org.refcodes.exception.MarshalException
This method creates / retrieves an instance of the given type with the given identifier (name) constructed as defined in one to many configuration files. How the instance is configured, created or retrieved is up to the nature (implementation) of the according factory.- Specified by:
toMarshaled
in interfaceMarshalable<java.lang.String>
- Parameters:
aObject
- The context which may influence the object being created by this factory.- Returns:
- The instance being fabricated by this factory.
- Throws:
org.refcodes.exception.MarshalException
- Thrown when marshaling / serializing an object fails.
-
toUnmarshaled
public <T> T toUnmarshaled(java.lang.String aHttpBody, java.lang.Class<T> aType) throws org.refcodes.exception.UnmarshalException
This method creates / retrieves an instance of the given type from the provided instance.- Specified by:
toUnmarshaled
in interfaceUnmarshalable<java.lang.String>
- Type Parameters:
T
- The type which is to be fabricated by the factory method.- Parameters:
aHttpBody
- The context which may influence the object being created by this factory.aType
- The type identifying the instance to be created / retrieved.- Returns:
- An instance of the required type for the given type and context.
- Throws:
org.refcodes.exception.UnmarshalException
- Thrown when unmarshaling / deserializing an object fails.
-
toPlainJson
protected java.lang.String toPlainJson(java.lang.String aJson)
Removes any prefixed variable declaration.- Parameters:
aJson
- The JSON from which to remove any prefixed variable declaration.- Returns:
- The JSON without any prefixed variable declaration.
-
toUnboxed
protected java.lang.String toUnboxed(java.lang.String aJson)
Unboxes any enveloped JSON.- Parameters:
aJson
- The JSON to be unboxed.- Returns:
- The unboxed JSON.
-
toElementName
protected java.lang.String toElementName(java.lang.Class<?> aClass)
Creates an element name for the class.- Parameters:
aClass
- The class from which to retrieve the element name.- Returns:
- The element name for the class.
-
toVariableDeclaration
protected java.lang.String toVariableDeclaration(java.lang.Class<?> aClass)
Returns the JSON specific assignment declaration for the given class.- Parameters:
aClass
- The class for which to construct the assignment declaration.- Returns:
- The according assignment declaration.
-
-