Class UonSerializer
- All Implemented Interfaces:
Function<Object,,String> ThrowingFunction<Object,,String> HttpPartSerializer,RecordWritable,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 output (Map of name/age):
(name=Alice,age=30)
Complex (nested object + array):
(name=Alice,age=30,address=(street=123+Main+St,city=Boston,state=MA),tags=@(a,b,c))
Example:
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUonSerializer.Builder<SELF extends UonSerializer.Builder<SELF>>Builder class.static final classstatic classEquivalent toUonSerializer..create ().encoding().build();static classEquivalent toUonSerializer..create ().ws().build();Nested classes/interfaces inherited from class org.apache.juneau.marshall.serializer.Serializer
Serializer.NullNested classes/interfaces inherited from interface org.apache.juneau.marshall.httppart.HttpPartSerializer
HttpPartSerializer.Creator, HttpPartSerializer.Void -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanstatic final UonSerializerReusable instance ofUonSerializer, all default settings.static final UonSerializerReusable instance ofUonSerializer.Encoding.static final UonSerializerReusable instance ofUonSerializer.Readable.protected final booleanprotected final ParamFormatprotected final CharacterFields inherited from class org.apache.juneau.marshall.serializer.WriterSerializer
maxIndent, quoteChar, quoteCharOverride, useWhitespaceFields inherited from class org.apache.juneau.marshall.serializer.Serializer
accept, addBeanTypes, addRootType, keepNullProperties, listener, nonDefault, produces, sortCollections, sortMaps, trimEmptyCollections, trimEmptyMaps, trimStringsFields inherited from class org.apache.juneau.marshall.MarshallingContextable
marshallingContextFields inherited from class org.apache.juneau.marshall.Context
CONTEXT_APPLY_FILTER -
Constructor Summary
Constructors -
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 ParamFormatFormat to use for query/form-data/header values.Creates a new serializer session.protected final charQuote 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 booleanAdd"_type" properties when needed.protected final booleanEncode non-valid URI characters.booleanStreaming-quality signal queryable before opening a cursor.Returns the properties on this bean as a map for debugging.write(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.writeRecords(Object output) Convenience delegator that opens a whole-valueRecordWriterover the output using default session arguments (mirrorsWriterSerializer.write(Object)).Methods inherited from class org.apache.juneau.marshall.serializer.WriterSerializer
applyThrows, getMaxIndent, getStreamCharset, isUseWhitespace, isWriterSerializer, println, quoteChar, toString, writeMethods inherited from class org.apache.juneau.marshall.serializer.Serializer
createSerializerBuilder, doWrite, forEachAcceptMediaType, getListener, getMediaTypeRanges, getPrimaryMediaType, getResponseContentType, getResponseHeaders, getUriContext, getUriRelativity, getUriResolution, isAddRootType, isKeepNullProperties, isNonDefault, isSortCollections, isSortMaps, isTrimEmptyCollections, isTrimEmptyMaps, isTrimStrings, write, writeToStringMethods inherited from class org.apache.juneau.marshall.MarshallingTraverseContext
getDetectRecursions, getIgnoreRecursions, getInitialDepth, getMaxDepth, isDetectRecursions, isIgnoreRecursions, shouldDetectRecursionsMethods inherited from class org.apache.juneau.marshall.MarshallingContextable
getDurationFormat, getMarshallingContext, getPeriodFormatMethods inherited from class org.apache.juneau.marshall.Context
createBuilder, getAnnotationProvider, init, isDebug, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.commons.function.ThrowingFunction
apply
-
Field Details
-
DEFAULT
Reusable instance ofUonSerializer, all default settings. -
DEFAULT_READABLE
Reusable instance ofUonSerializer.Readable. -
DEFAULT_ENCODING
Reusable instance ofUonSerializer.Encoding. -
addBeanTypesUon
-
encoding
-
quoteCharUon
-
paramFormat
-
-
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.
-
copy
Description copied from class:ContextCreates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
- Overrides:
copyin classWriterSerializer- Returns:
- A new Builder object.
-
createSession
Description copied from class:ContextCreate 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:
createSessionin classWriterSerializer- Returns:
- A new session builder.
-
getPartSession
Description copied from interface:HttpPartSerializerCreates a new serializer session.- Specified by:
getPartSessionin interfaceHttpPartSerializer- Returns:
- A new serializer session.
-
getSession
Description copied from class:ContextReturns a session to use for this context.Note that subclasses may opt to return a reusable non-modifiable session.
- Overrides:
getSessionin classWriterSerializer- Returns:
- A new session object.
-
writeRecords
Convenience delegator that opens a whole-valueRecordWriterover the output using default session arguments (mirrorsWriterSerializer.write(Object)).The real implementation lives on
UonSerializerSession.writeRecords(Object). Callers that need request-derived configuration should callcreateSession()and invokeUonSerializerSession.writeRecords(Object)on the built session instead.- Specified by:
writeRecordsin interfaceRecordWritable- Parameters:
output- The output.- Returns:
- A new
RecordWriter. - Throws:
IOException- If a problem occurred opening the underlying output.
-
isRecordStreaming
Description copied from interface:RecordWritableStreaming-quality signal queryable before opening a cursor.- Specified by:
isRecordStreamingin interfaceRecordWritable- Returns:
true ifRecordWritable.writeRecords(Object)returns an O(1)-memory streaming cursor;false for buffered (whole-value) formats backed byRecordAdapter.
-
getUonBeanPropertyMeta
Description copied from interface:UonMetaProviderReturns the language-specific metadata on the specified bean property.- Specified by:
getUonBeanPropertyMetain interfaceUonMetaProvider- Parameters:
bpm- The bean property to return the metadata on.- Returns:
- The metadata.
-
getUonClassMeta
Description copied from interface:UonMetaProviderReturns the language-specific metadata on the specified class.- Specified by:
getUonClassMetain interfaceUonMetaProvider- Parameters:
cm- The class to return the metadata on.- Returns:
- The metadata.
-
write
public String write(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.
-
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:
getQuoteCharin classWriterSerializer- Returns:
- The character used for quoting attributes and values.
- See Also:
-
isAddBeanTypes
Add"_type" properties when needed.- Overrides:
isAddBeanTypesin 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:
-
properties
Description copied from class:ContextReturns the properties on this bean as a map for debugging.- Overrides:
propertiesin classWriterSerializer- Returns:
- The properties on this bean as a map for debugging.
-