Class WriterSerializer
java.lang.Object
org.apache.juneau.marshall.Context
org.apache.juneau.marshall.MarshallingContextable
org.apache.juneau.marshall.MarshallingTraverseContext
org.apache.juneau.marshall.serializer.Serializer
org.apache.juneau.marshall.serializer.WriterSerializer
- Direct Known Subclasses:
CsvSerializer,HjsonSerializer,HoconSerializer,IniSerializer,JsonSerializer,MarkdownSerializer,PlainTextSerializer,RdfSerializer,SseSerializer,TomlSerializer,UonSerializer,XmlSerializer,YamlSerializer
Subclass of
Serializer for character-based serializers.
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class.static final classNested classes/interfaces inherited from class org.apache.juneau.marshall.serializer.Serializer
Serializer.Null -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intprotected final Characterprotected final Characterprotected final booleanFields 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
ConstructorsModifierConstructorDescriptionprotectedWriterSerializer(WriterSerializer.Builder<?> builder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal StringAllows this serializer to be used as aThrowingFunctionthat converts an object to its serialized string form.copy()Creates a builder from this context object.static WriterSerializer.Builder<?>create()Creates a new builder for this object.Create a session builder based on the properties defined on this context.protected final intMaximum indentation.protected charQuote character.Returns a session to use for this context.protected final CharsetOutput stream charset.protected final booleanUse whitespace.final booleanReturnstrue if this serializer subclasses fromWriterSerializer.final WriterSerializerConvenience method for serializing an object and sending it to STDOUT.Returns the properties on this bean as a map for debugging.protected CharacterQuote character.final Stringfinal StringConvenience method for serializing an object to aString .Methods inherited from class org.apache.juneau.marshall.serializer.Serializer
createSerializerBuilder, doWrite, forEachAcceptMediaType, getListener, getMediaTypeRanges, getPrimaryMediaType, getResponseContentType, getResponseHeaders, getUriContext, getUriRelativity, getUriResolution, isAddBeanTypes, 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
-
useWhitespace
-
quoteChar
-
quoteCharOverride
-
maxIndent
-
-
Constructor Details
-
WriterSerializer
Constructor.- Parameters:
builder- The builder for this object.
Cannot benull .
-
-
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 classSerializer- 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 classSerializer- Returns:
- A new session builder.
-
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 classSerializer- Returns:
- A new session object.
-
isWriterSerializer
Description copied from class:SerializerReturnstrue if this serializer subclasses fromWriterSerializer.- Overrides:
isWriterSerializerin classSerializer- Returns:
true if this serializer subclasses fromWriterSerializer.
-
println
Convenience method for serializing an object and sending it to STDOUT.- Parameters:
o- The object to serialize.- Returns:
- This object.
-
write
Convenience method for serializing an object to aString .- Overrides:
writein classSerializer- Parameters:
o- The object to serialize.- Returns:
- The output serialized to a string.
- Throws:
SerializeException- If a problem occurred trying to convert the output.
-
applyThrows
Allows this serializer to be used as aThrowingFunctionthat converts an object to its serialized string form.Because
WriterSerializerimplementsThrowingFunction<Object,String>, a serializer instance can be passed directly wherever aFunctionorThrowingFunctionis expected (e.g. assertion transform methods).Example:
assertObject (myPojo ).asString(Json5Serializer.DEFAULT ).is("{...}" );- Specified by:
applyThrowsin interfaceThrowingFunction<Object,String> - Parameters:
o- The object to serialize.- Returns:
- The output serialized to a string.
- Throws:
Exception- If a problem occurred trying to convert the output.
-
toString
Identical towrite(Object)except throws aRuntimeExceptioninstead of aSerializeException.This is typically good enough for debugging purposes.
- Parameters:
o- The object to serialize.- Returns:
- The serialized object.
-
getMaxIndent
Maximum indentation.- Returns:
- The maximum indentation level in the serialized document.
- See Also:
-
getQuoteChar
Quote character.- Returns:
- The character used for quoting attributes and values.
- See Also:
-
getStreamCharset
Output stream charset.- Returns:
- The character set to use when writing to
OutputStreams and byte arrays. - See Also:
-
isUseWhitespace
Use whitespace.- Returns:
- When enabled, whitespace is added to the output to improve readability.
- See Also:
-
properties
Description copied from class:ContextReturns the properties on this bean as a map for debugging.- Overrides:
propertiesin classSerializer- Returns:
- The properties on this bean as a map for debugging.
-
quoteChar
Quote character.- Returns:
- The character used for quoting attributes and values.
- See Also:
-