Class UonSerializer
- All Implemented Interfaces:
AnnotationProvider
,HttpPartSerializer
,UonMetaProvider
- Direct Known Subclasses:
OpenApiSerializer
,UonSerializer.Encoding
,UonSerializer.Readable
,UrlEncodingSerializer
Media types
Handles
Produces
Description
This serializer provides several serialization options. Typically, one of the predefined DEFAULT serializers will be sufficient. However, custom serializers can be constructed to fine-tune behavior.
The following shows a sample object defined in Javascript:
{
id: 1,
name:
Using the "strict" syntax defined in this document, the equivalent UON notation would be as follows:
(
Example:
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder class.static class
Equivalent toUonSerializer.
.create ().encoding().build();static class
Equivalent toUonSerializer.
.create ().ws().build();Nested classes/interfaces inherited from class org.apache.juneau.serializer.Serializer
Serializer.Null
Nested classes/interfaces inherited from interface org.apache.juneau.httppart.HttpPartSerializer
HttpPartSerializer.Creator, HttpPartSerializer.Void
-
Field Summary
Modifier and TypeFieldDescriptionstatic final UonSerializer
Reusable instance ofUonSerializer
, all default settings.static final UonSerializer
Reusable instance ofUonSerializer.Encoding
.static final UonSerializer
Reusable instance ofUonSerializer.Readable
.Fields inherited from class org.apache.juneau.Context
CONTEXT_APPLY_FILTER
Fields inherited from interface org.apache.juneau.AnnotationProvider
DISABLE_ANNOTATION_CACHING
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates a builder from this context object.static UonSerializer.Builder
create()
Creates a new builder for this object.Create a session builder based on the properties defined on this context.protected final ParamFormat
Format to use for query/form-data/header values.Creates a new serializer session.protected final char
Quote character.Returns a session to use for this context.Returns the language-specific metadata on the specified bean property.getUonClassMeta
(ClassMeta<?> cm) Returns the language-specific metadata on the specified class.protected final boolean
Add"_type" properties when needed.protected final boolean
Encode non-valid URI characters.protected JsonMap
Returns the properties on this bean as a map for debugging.serialize
(HttpPartType partType, HttpPartSchema schema, Object value) Converts the specified value to a string that can be used as an HTTP header value, query parameter value, form-data parameter, or URI path variable.Methods inherited from class org.apache.juneau.serializer.WriterSerializer
getFileCharset, getMaxIndent, getStreamCharset, isUseWhitespace, isWriterSerializer, println, quoteChar, serialize, toString
Methods inherited from class org.apache.juneau.serializer.Serializer
createSerializerBuilder, doSerialize, forEachAcceptMediaType, getListener, getMediaTypeRanges, getPrimaryMediaType, getResponseContentType, getResponseHeaders, getUriContext, getUriRelativity, getUriResolution, isAddRootType, isKeepNullProperties, isSortCollections, isSortMaps, isTrimEmptyCollections, isTrimEmptyMaps, isTrimStrings, serialize, serializeToString
Methods inherited from class org.apache.juneau.BeanTraverseContext
getInitialDepth, getMaxDepth, isDetectRecursions, isIgnoreRecursions
Methods inherited from class org.apache.juneau.BeanContextable
getBeanContext
Methods inherited from class org.apache.juneau.Context
createBuilder, firstAnnotation, firstAnnotation, firstAnnotation, firstAnnotation, firstDeclaredAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachDeclaredAnnotation, hasAnnotation, hasAnnotation, hasAnnotation, hasAnnotation, init, isDebug, lastAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastDeclaredAnnotation, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.juneau.AnnotationProvider
firstAnnotation, firstAnnotation, firstAnnotation, firstAnnotation, firstDeclaredAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachDeclaredAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastDeclaredAnnotation
-
Field Details
-
DEFAULT
Reusable instance ofUonSerializer
, all default settings. -
DEFAULT_READABLE
Reusable instance ofUonSerializer.Readable
. -
DEFAULT_ENCODING
Reusable instance ofUonSerializer.Encoding
.
-
-
Constructor Details
-
UonSerializer
Constructor.- Parameters:
builder
- The builder for this object.
-
-
Method Details
-
create
Creates a new builder for this object.- Returns:
- A new builder.
-
serialize
public String serialize(HttpPartType partType, HttpPartSchema schema, Object value) throws SchemaValidationException, SerializeException Converts the specified value to a string that can be used as an HTTP header value, query parameter value, form-data parameter, or URI path variable.Returned values should NOT be URL-encoded.
- Parameters:
partType
- The category of value being serialized.schema
- Schema information about the part.
May benull .
Not all part serializers use the schema information.value
- The value being serialized.- Returns:
- The serialized value.
- Throws:
SerializeException
- If a problem occurred while trying to parse the input.SchemaValidationException
- If the output fails schema validation.
-
copy
Description copied from class:Context
Creates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
- Overrides:
copy
in classWriterSerializer
- Returns:
- A new Builder object.
-
createSession
Description copied from class:Context
Create a session builder based on the properties defined on this context.Use this method for creating sessions where you want to override basic settings. Otherwise, use
Context.getSession()
directly.- Overrides:
createSession
in classWriterSerializer
- Returns:
- A new session builder.
-
getSession
Description copied from class:Context
Returns a session to use for this context.Note that subclasses may opt to return a reusable non-modifiable session.
- Overrides:
getSession
in classWriterSerializer
- Returns:
- A new session object.
-
getPartSession
Description copied from interface:HttpPartSerializer
Creates a new serializer session.- Specified by:
getPartSession
in interfaceHttpPartSerializer
- Returns:
- A new serializer session.
-
getUonClassMeta
Description copied from interface:UonMetaProvider
Returns the language-specific metadata on the specified class.- Specified by:
getUonClassMeta
in interfaceUonMetaProvider
- Parameters:
cm
- The class to return the metadata on.- Returns:
- The metadata.
-
getUonBeanPropertyMeta
Description copied from interface:UonMetaProvider
Returns the language-specific metadata on the specified bean property.- Specified by:
getUonBeanPropertyMeta
in interfaceUonMetaProvider
- Parameters:
bpm
- The bean property to return the metadata on.- Returns:
- The metadata.
-
isAddBeanTypes
Add"_type" properties when needed.- Overrides:
isAddBeanTypes
in classSerializer
- Returns:
true if"_type" properties will be added to beans if their type cannot be inferred through reflection.- See Also:
-
isEncoding
Encode non-valid URI characters.- Returns:
true if non-valid URI characters should be encoded with"%xx" constructs.- See Also:
-
getParamFormat
Format to use for query/form-data/header values.- Returns:
- Specifies the format to use for URL GET parameter keys and values.
- See Also:
-
getQuoteChar
Quote character.- Overrides:
getQuoteChar
in classWriterSerializer
- Returns:
- The character used for quoting attributes and values.
- See Also:
-
properties
Description copied from class:Context
Returns the properties on this bean as a map for debugging.- Overrides:
properties
in classWriterSerializer
- Returns:
- The properties on this bean as a map for debugging.
-