Class BsonSerializer.Builder
- Enclosing class:
- BsonSerializer
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder()Constructor, default settings.protectedBuilder(BsonSerializer copyFrom) Copy constructor.protectedBuilder(BsonSerializer.Builder copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddBeanTypesBson(boolean value) Add"_type" properties when needed.Add type attribute to root nodes.addRootType(boolean value) Same asSerializer.Builder.addRootType()but allows you to explicitly specify the value.binaryFormat(BinaryFormat value) Binary wire format.build()Build the object.copy()Copy creator.hashKey()Returns the hashkey of this builder.Don't trim null bean property values.keepNullProperties(boolean value) Same asSerializer.Builder.keepNullProperties()but allows you to explicitly specify the value.nullKeyString(String value) The string used to representnull map keys in BSON documents.writeDatesAsDatetime(boolean value) Use BSON datetime type for dates.Methods inherited from class org.apache.juneau.marshall.serializer.Serializer.Builder
accept, addBeanTypes, addBeanTypes, getAccept, getProduces, listener, nonDefault, nonDefault, produces, sortCollections, sortCollections, sortMaps, sortMaps, trimEmptyCollections, trimEmptyCollections, trimEmptyMaps, trimEmptyMaps, trimStrings, trimStrings, uriContext, uriRelativity, uriResolutionMethods inherited from class org.apache.juneau.marshall.MarshallingTraverseContext.Builder
detectRecursions, detectRecursions, ignoreRecursions, ignoreRecursions, initialDepth, maxDepthMethods inherited from class org.apache.juneau.marshall.MarshallingContextable.Builder
activeView, annotations, beanClassVisibility, beanConstructorVisibility, beanDictionary, beanFieldVisibility, beanInterceptor, beanMapPutReturnsOldValue, beanMethodVisibility, beanProperties, beanProperties, beanProperties, beanPropertiesExcludes, beanPropertiesExcludes, beanPropertiesExcludes, beanPropertiesReadOnly, beanPropertiesReadOnly, beanPropertiesReadOnly, beanPropertiesWriteOnly, beanPropertiesWriteOnly, beanPropertiesWriteOnly, beansRequireDefaultConstructor, beansRequireSerializable, beansRequireSettersForGetters, bigNumberFormat, bitSetFormat, booleanFormat, calendarFormat, classFormat, classLoader, currencyFormat, dateFormat, debug, dictionaryOn, disableBeansRequireSomeProperties, disableDefaultViewInclusion, disableIgnoreMissingSetters, disableIgnoreTransientFields, disableIgnoreUnknownNullBeanProperties, disableInterfaceProxies, durationFormat, enumFormat, example, example, findFluentSetters, findFluentSetters, floatFormat, ignoreInvocationExceptionsOnGetters, ignoreInvocationExceptionsOnSetters, ignoreUnknownBeanProperties, ignoreUnknownEnumValues, implClass, implClasses, interfaceClass, interfaces, locale, localeFormat, marshallingContext, marshallingContext, marshallingContext, marshallingContext, mediaType, notBeanClasses, notBeanPackages, periodFormat, propertyNamer, propertyNamer, recordComponentOrder, stopClass, swap, swap, swaps, swaps, temporalFormat, timeZone, timeZoneFormat, typeName, typePropertyName, typePropertyName, unsortedProperties, unsortedProperties, useJavaBeanIntrospector, uuidFormat, validateSchema, validateSchemaMethods inherited from class org.apache.juneau.marshall.Context.Builder
annotations, apply, applyAnnotations, applyAnnotations, asSubtype, build, cache, canApply, copyOrNull, debug, getApplied, getType, impl, isDebug, registerBuilders, self, type
-
Constructor Details
-
Builder
protected Builder()Constructor, default settings. -
Builder
Copy constructor.- Parameters:
copyFrom- The builder to copy from.
Cannot benull .
-
Builder
Copy constructor.- Parameters:
copyFrom- The bean to copy from.
Cannot benull .
-
-
Method Details
-
addBeanTypesBson
Add"_type" properties when needed.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
nullKeyString
The string used to representnull map keys in BSON documents.BSON document field names cannot be
null . When serializing aMapwith anull key, this string is used as the field name. When parsing, a field with this name is stored withnull as the key.- Parameters:
value- The placeholder string for null keys. Default is"<NULL>" .- Returns:
- This object.
-
writeDatesAsDatetime
Use BSON datetime type for dates. Whenfalse , dates are serialized as ISO-8601 strings.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
binaryFormat
Description copied from class:MarshallingContextable.BuilderBinary wire format.- Overrides:
binaryFormatin classMarshallingContextable.Builder<BsonSerializer.Builder>- Parameters:
value- The new value for this property.
Can benull (defaults toBinaryFormat.NOT_SET).- Returns:
- This object.
-
keepNullProperties
Description copied from class:Serializer.BuilderDon't trim null bean property values.When enabled, null bean values will be serialized to the output.
Notes:
- Not enabling this setting will cause
Map s withnull values to be lost during parsing.
Example:
// Create a serializer that serializes null properties. WriterSerializerserializer = JsonSerializer .create () .keepNullProperties() .build();// Our bean to serialize. public class MyBean {public Stringfoo =null ; }// Will contain "{foo:null}". Stringjson =serializer .write(new MyBean());Token streams: the cursor's raw structural methods always emit what the caller asks for; however this setting IS honored by
TokenWriter.object(Object)during a bean walk.- Overrides:
keepNullPropertiesin classSerializer.Builder<BsonSerializer.Builder>- Returns:
- This object.
- Not enabling this setting will cause
-
keepNullProperties
Description copied from class:Serializer.BuilderSame asSerializer.Builder.keepNullProperties()but allows you to explicitly specify the value.- Overrides:
keepNullPropertiesin classSerializer.Builder<BsonSerializer.Builder>- Parameters:
value- The value for this setting.- Returns:
- This object.
-
addRootType
Description copied from class:Serializer.BuilderAdd type attribute to root nodes.When enabled,
"_type" properties will be added to top-level beans.When disabled, it is assumed that the parser knows the exact Java POJO type being parsed, and therefore top-level type information that might normally be included to determine the data type will not be serialized.
For example, when serializing a top-level POJO with a
@Marshalled(typeName)value, a'_type' attribute will only be added when this setting is enabled.Note the differences between the following settings:
Serializer.Builder.addRootType()- Affects whether'_type' is added to root node.Serializer.Builder.addBeanTypes()- Affects whether'_type' is added to any nodes.
Example:
// Create a serializer that adds _type to root node. WriterSerializerserializer = JsonSerializer .create () .addRootType() .build();// Our bean to serialize. @Marshalled (typeName="mybean" )public class MyBean {public Stringfoo ="bar" ; }// Will contain: {"_type":"mybean","foo":"bar"} Stringjson =serializer .write(new MyBean());Token streams: the cursor's raw structural methods do not emit
"_type" ; however this setting IS honored byTokenWriter.object(Object)for the root value.- Overrides:
addRootTypein classSerializer.Builder<BsonSerializer.Builder>- Returns:
- This object.
-
addRootType
Description copied from class:Serializer.BuilderSame asSerializer.Builder.addRootType()but allows you to explicitly specify the value.- Overrides:
addRootTypein classSerializer.Builder<BsonSerializer.Builder>- Parameters:
value- The value for this setting.- Returns:
- This object.
-
build
Description copied from class:Context.BuilderBuild the object.- Overrides:
buildin classOutputStreamSerializer.Builder<BsonSerializer.Builder>- Returns:
- The built object.
-
hashKey
Description copied from class:Context.BuilderReturns the hashkey of this builder.Used to return previously instantiated context beans that have matching hashkeys. The
HashKeyobject is suitable for use as a hashmap key of a map of context beans. A context bean is considered equivalent if theHashKey.equals(Object)method is the same.- Overrides:
hashKeyin classSerializer.Builder<BsonSerializer.Builder>- Returns:
- The hashkey of this builder.
-
copy
Description copied from class:Context.BuilderCopy creator.- Specified by:
copyin classOutputStreamSerializer.Builder<BsonSerializer.Builder>- Returns:
- A new mutable copy of this builder.
-