Class MarshallingTraverseContext.Builder<SELF extends MarshallingTraverseContext.Builder<SELF>>
- Direct Known Subclasses:
JsonSchemaGenerator.Builder,Serializer.Builder
- Enclosing class:
- MarshallingTraverseContext
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder()Constructor, default settings.protectedBuilder(MarshallingTraverseContext copyFrom) Copy constructor.protectedBuilder(MarshallingTraverseContext.Builder<?> copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionAutomatically detect POJO recursions.detectRecursions(boolean value) Same asdetectRecursions()but allows you to explicitly specify the value.hashKey()Returns the hashkey of this builder.Ignore recursion errors.ignoreRecursions(boolean value) Same asignoreRecursions()but allows you to explicitly specify the value.initialDepth(int value) Initial depth.maxDepth(int value) Max traversal depth.Methods 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, binaryFormat, bitSetFormat, booleanFormat, calendarFormat, classFormat, classLoader, copy, 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, 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 bean to copy from. Cannot benull .
-
Builder
Copy constructor.- Parameters:
copyFrom- The builder to copy from. Cannot benull .
-
-
Method Details
-
detectRecursions
Automatically detect POJO recursions.When enabled, specifies that recursions should be checked for during traversal.
Recursions can occur when traversing models that aren't true trees but rather contain loops.
When recursion detection is disabled, such loops are instead bounded bymaxDepth(default100 ): the over-depth branch is silently truncated, producing finite but semantically-incomplete output.
If the stack is exhausted beforemaxDepth is reached, the resultingStackOverflowErroris converted to aMarshallingRecursionExceptionwith the message"Depth too deep. Stack overflow occurred." .Notes:
- Checking for recursion can cause a small performance penalty.
-
This is the recommended way to fail-fast on cyclic bean graphs such as parent/child
@ParentPropertyreferences. Under the default config such cycles are instead silently truncated atmaxDepth(see theParentPropertyJavadoc).
Example:
// Create a serializer that automatically checks for recursions. WriterSerializerserializer = JsonSerializer .create () .detectRecursions() .build();// Create a POJO model with a recursive loop. public class MyBean {public Objectf ; } MyBeanbean =new MyBean();bean .f =bean ;// Throws a SerializeException and not a StackOverflowError Stringjson =serializer .write(bean );- Returns:
- This object.
-
detectRecursions
Same asdetectRecursions()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This 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 classMarshallingContextable.Builder<SELF extends MarshallingTraverseContext.Builder<SELF>>- Returns:
- The hashkey of this builder.
-
ignoreRecursions
Ignore recursion errors.When enabled, when we encounter the same object when traversing a tree, we set the value to
null .For example, if a model contains the links A->B->C->A, then the JSON generated will look like the following when this setting is
true ...{A:{B:{C:
null }}}Notes:
- Checking for recursion can cause a small performance penalty.
-
Use this to serialize cyclic bean graphs (such as parent/child
@ParentPropertyreferences) by emitting the repeated node asnull so the output round-trips cleanly.
Example:
// Create a serializer ignores recursions. WriterSerializerserializer = JsonSerializer .create () .ignoreRecursions() .build();// Create a POJO model with a recursive loop. public class MyBean {public Objectf ; } MyBeanbean =new MyBean();bean .f =bean ;// Produces "{f:null}" Stringjson =serializer .write(bean );- Returns:
- This object.
-
ignoreRecursions
Same asignoreRecursions()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
initialDepth
Initial depth.The initial indentation level at the root.
Useful when constructing document fragments that need to be indented at a certain level when whitespace is enabled.
Example:
// Create a serializer with whitespace enabled and an initial depth of 2. WriterSerializerserializer = JsonSerializer .create () .ws() .initialDepth(2) .build();// Produces "\t\t{\n\t\t\t'foo':'bar'\n\t\t}\n" Stringjson =serializer .write(new MyBean());- Parameters:
value- The new value for this setting.
The default is0 .- Returns:
- This object.
-
maxDepth
Max traversal depth.Specifies the maximum depth traversed in the POJO tree.
When this depth is exceeded, the over-depth nodes are silently dropped (truncated) from the output — no exception is thrown. This is a size guard that bounds the output of deeply-nested (or cyclic) models; it is not a cycle detector. For genuine recursive references, enable
detectRecursions()to fail-fast with aMarshallingRecursionException, orignoreRecursions()to emit repeated nodes asnull so the output round-trips cleanly.Example:
// Create a serializer that truncates output beyond a depth of 20. WriterSerializerserializer = JsonSerializer .create () .maxDepth(20) .build();See Also:
- Parameters:
value- The new value for this setting.
The default is100 .- Returns:
- This object.
-