Class JsonSerializer
- All Implemented Interfaces:
- AnnotationProvider,- JsonMetaProvider
- Direct Known Subclasses:
- Json5Serializer,- JsonSchemaSerializer,- JsonSerializer.Readable,- JsonSerializer.ReadableSafe
Media types
 Handles 
 Produces 
Description
The conversion is as follows...
- 
      Maps (e.g. HashMaps,TreeMaps) are converted to JSON objects.
- 
      Collections (e.g. HashSets,LinkedLists) and Java arrays are converted to JSON arrays.
- 
      Stringsare converted to JSON strings.
- 
      Numbers(e.g.Integer,Long,Double) are converted to JSON numbers.
- 
      Booleansare converted to JSON booleans.
- 
      nullsare converted to JSON nulls.
- 
      arraysare converted to JSON arrays.
- 
      beansare converted to JSON objects.
 The types above are considered "JSON-primitive" object types.
 Any non-JSON-primitive object types are transformed into JSON-primitive object types through
 ObjectSwaps associated through the
 BeanContext.Builder.swaps(Class...) method.
 Several default transforms are provided for transforming Dates, Enums, Iterators, etc...
 
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.
Behavior-specific subclasses
The following direct subclasses are provided for convenience:
- 
      Json5Serializer- Default serializer, single quotes, simple mode.
- 
      Json5Serializer.Readable- Default serializer, single quotes, simple mode, with whitespace.
Example:
   
Notes:
- This class is thread safe and reusable.
See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classBuilder class.static classDefault serializer, with whitespace.static classDefault serializer, single quotes, simple mode, with whitespace and recursion detection.Nested classes/interfaces inherited from class org.apache.juneau.serializer.SerializerSerializer.Null
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final JsonSerializerDefault serializer, all default settings.static final JsonSerializerDefault serializer, all default settings.static final JsonSerializerDefault serializer, single quotes,simple mode, sorted bean properties.Fields inherited from class org.apache.juneau.ContextCONTEXT_APPLY_FILTERFields inherited from interface org.apache.juneau.AnnotationProviderDISABLE_ANNOTATION_CACHING
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptioncopy()Creates a builder from this context object.static JsonSerializer.Buildercreate()Creates a new builder for this object.Create a session builder based on the properties defined on this context.Returns the language-specific metadata on the specified bean property.getJsonClassMeta(ClassMeta<?> cm) Returns the language-specific metadata on the specified class.Returns the schema serializer based on the settings of this serializer.Returns a session to use for this context.protected final booleanAdd"_type" properties when needed.protected final booleanPrefix solidus'/' characters with escapes.protected final booleanSimple JSON mode.protected JsonMapReturns the properties on this bean as a map for debugging.Methods inherited from class org.apache.juneau.serializer.WriterSerializergetFileCharset, getMaxIndent, getQuoteChar, getStreamCharset, isUseWhitespace, isWriterSerializer, println, quoteChar, serialize, toStringMethods inherited from class org.apache.juneau.serializer.SerializercreateSerializerBuilder, doSerialize, forEachAcceptMediaType, getListener, getMediaTypeRanges, getPrimaryMediaType, getResponseContentType, getResponseHeaders, getUriContext, getUriRelativity, getUriResolution, isAddRootType, isKeepNullProperties, isSortCollections, isSortMaps, isTrimEmptyCollections, isTrimEmptyMaps, isTrimStrings, serialize, serializeToStringMethods inherited from class org.apache.juneau.BeanTraverseContextgetInitialDepth, getMaxDepth, isDetectRecursions, isIgnoreRecursionsMethods inherited from class org.apache.juneau.BeanContextablegetBeanContextMethods inherited from class org.apache.juneau.ContextcreateBuilder, firstAnnotation, firstAnnotation, firstAnnotation, firstAnnotation, firstDeclaredAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachDeclaredAnnotation, hasAnnotation, hasAnnotation, hasAnnotation, hasAnnotation, init, isDebug, lastAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastDeclaredAnnotation, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.AnnotationProviderfirstAnnotation, firstAnnotation, firstAnnotation, firstAnnotation, firstDeclaredAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachDeclaredAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastDeclaredAnnotation
- 
Field Details- 
DEFAULTDefault serializer, all default settings.
- 
DEFAULT_SORTEDDefault serializer, single quotes,simple mode, sorted bean properties.
- 
DEFAULT_READABLEDefault serializer, all default settings.
 
- 
- 
Constructor Details- 
JsonSerializerConstructor.- Parameters:
- builder- The builder for this object.
 
 
- 
- 
Method Details- 
createCreates a new builder for this object.- Returns:
- A new builder.
 
- 
copyDescription 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 class- WriterSerializer
- Returns:
- A new Builder object.
 
- 
createSessionDescription 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 class- WriterSerializer
- Returns:
- A new session builder.
 
- 
getSessionDescription 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 class- WriterSerializer
- Returns:
- A new session object.
 
- 
getSchemaSerializerReturns the schema serializer based on the settings of this serializer.Note that this method creates a builder initialized to all default settings, whereas copy()copies the settings of the object called on.- Returns:
- The schema serializer.
 
- 
getJsonClassMetaDescription copied from interface:JsonMetaProviderReturns the language-specific metadata on the specified class.- Specified by:
- getJsonClassMetain interface- JsonMetaProvider
- Parameters:
- cm- The class to return the metadata on.
- Returns:
- The metadata.
 
- 
getJsonBeanPropertyMetaDescription copied from interface:JsonMetaProviderReturns the language-specific metadata on the specified bean property.- Specified by:
- getJsonBeanPropertyMetain interface- JsonMetaProvider
- Parameters:
- bpm- The bean property to return the metadata on.
- Returns:
- The metadata.
 
- 
isAddBeanTypesAdd"_type" properties when needed.- Overrides:
- isAddBeanTypesin class- Serializer
- Returns:
- true if- "_type" properties will be added to beans if their type cannot be inferred through reflection.
- See Also:
 
- 
isEscapeSolidusPrefix solidus'/' characters with escapes.- Returns:
- true if solidus (e.g. slash) characters should be escaped.
- See Also:
 
- 
isSimpleAttrsSimple JSON mode.- Returns:
- true if JSON attribute names will only be quoted when necessary.
 Otherwise, they are always quoted.
- See Also:
 
- 
propertiesDescription copied from class:ContextReturns the properties on this bean as a map for debugging.- Overrides:
- propertiesin class- WriterSerializer
- Returns:
- The properties on this bean as a map for debugging.
 
 
-