Package org.apache.juneau
Class BeanTraverseSession
java.lang.Object
org.apache.juneau.ContextSession
org.apache.juneau.BeanSession
org.apache.juneau.BeanTraverseSession
- Direct Known Subclasses:
JsonSchemaGeneratorSession
,SerializerSession
ContextSession that lives for the duration of a single use of
BeanTraverseContext
.
Used by serializers and other classes that traverse POJOs for the following purposes:
- Keeping track of how deep it is in a model for indentation purposes.
- Ensuring infinite loops don't occur by setting a limit on how deep to traverse a model.
- Ensuring infinite loops don't occur from loops in the model (when detectRecursions is enabled.
Notes:
- This class is not thread safe and is typically discarded after one use.
See Also:
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Initial depth.final JsonMap
Returns information used to determine at what location in the parse a failure occurred.final int
Max traversal depth.protected final ClassMeta<?>
getOptionalType
(ClassMeta<?> cm) Returns the inner type of anOptional
.protected final Object
If the specified object is anOptional
, returns the inner object.protected String
getStack
(boolean full) Returns the current stack trace.final boolean
Automatically detect POJO recursions.final boolean
Ignore recursion errors.protected final boolean
isOptional
(ClassMeta<?> cm) Same asClassMeta.isOptional()
but gracefully handles a nullClassMeta
.protected final boolean
isRoot()
Returnstrue if we're processing the root node.protected void
Logs a warning message.protected final void
pop()
Pop an object off the stack.protected JsonMap
Returns the properties on this bean as a map for debugging.protected final ClassMeta<?>
Push the specified object onto the stack.protected final void
setCurrentClass
(ClassMeta<?> currentClass) Sets the current class being traversed for proper error messages.protected final void
setCurrentProperty
(BeanPropertyMeta currentProperty) Sets the current bean property being traversed for proper error messages.protected final boolean
Returnstrue if we're about to exceed the max depth for the document.protected final boolean
willRecurse
(String attrName, Object o, ClassMeta<?> cm) Returnstrue ifBeanTraverseContext.Builder.detectRecursions()
is enabled, and the specified object is already higher up in the traversal chain.Methods inherited from class org.apache.juneau.BeanSession
_class, addWarning, convertToMemberType, convertToMemberType, convertToType, convertToType, convertToType, create, getArgsClassMeta, getBeanClassVisibility, getBeanConstructorVisibility, getBeanDictionary, getBeanFieldVisibility, getBeanMeta, getBeanMethodVisibility, getBeanRegistry, getBeanTypePropertyName, getBeanTypePropertyName, getClassMeta, getClassMeta, getClassMetaForObject, getClassMetaForObject, getLocale, getMediaType, getNamePropertyName, getNotBeanClasses, getNotBeanPackagesNames, getNotBeanPackagesPrefixes, getPropertyNamer, getSwaps, getTimeZone, getTimeZoneId, isBean, isBean, isBeanMapPutReturnsOldValue, isBeansRequireDefaultConstructor, isBeansRequireSerializable, isBeansRequireSettersForGetters, isBeansRequireSomeProperties, isFindFluentSetters, isIgnoreInvocationExceptionsOnGetters, isIgnoreInvocationExceptionsOnSetters, isIgnoreMissingSetters, isIgnoreUnknownBeanProperties, isIgnoreUnknownNullBeanProperties, isSortProperties, isUseEnumNames, isUseInterfaceProxies, isUseJavaBeanIntrospector, newBean, newBean, newBeanMap, newBeanMap, newGenericMap, object, string, toArray, toBeanMap, toBeanMap, toBeanMap
Methods inherited from class org.apache.juneau.ContextSession
checkForWarnings, getContext, getSessionProperties, getWarnings, isDebug, toString
-
Field Details
-
indent
The current indentation depth into the model.
-
-
Constructor Details
-
BeanTraverseSession
Constructor.- Parameters:
builder
- The builder for this object.
-
-
Method Details
-
setCurrentProperty
Sets the current bean property being traversed for proper error messages.- Parameters:
currentProperty
- The current property being traversed.
-
setCurrentClass
Sets the current class being traversed for proper error messages.- Parameters:
currentClass
- The current class being traversed.
-
push
protected final ClassMeta<?> push(String attrName, Object o, ClassMeta<?> eType) throws BeanRecursionException Push the specified object onto the stack.- Parameters:
attrName
- The attribute name.o
- The current object being traversed.eType
- The expected class type.- Returns:
- The
ClassMeta
of the object so thatinstanceof operations only need to be performed once (since they can be expensive). - Throws:
BeanRecursionException
- If recursion occurred.
-
isRoot
Returnstrue if we're processing the root node.Must be called after
push(String, Object, ClassMeta)
and beforepop()
.- Returns:
true if we're processing the root node.
-
willRecurse
protected final boolean willRecurse(String attrName, Object o, ClassMeta<?> cm) throws BeanRecursionException Returnstrue ifBeanTraverseContext.Builder.detectRecursions()
is enabled, and the specified object is already higher up in the traversal chain.- Parameters:
attrName
- The bean property attribute name, or some other identifier.o
- The object to check for recursion.cm
- The metadata on the object class.- Returns:
true if recursion detected.- Throws:
BeanRecursionException
- If recursion occurred.
-
willExceedDepth
Returnstrue if we're about to exceed the max depth for the document.- Returns:
true if we're about to exceed the max depth for the document.
-
pop
Pop an object off the stack. -
isOptional
Same asClassMeta.isOptional()
but gracefully handles a nullClassMeta
.- Parameters:
cm
- The meta to check.- Returns:
true if the specified meta is anOptional
.
-
getOptionalType
Returns the inner type of anOptional
.- Parameters:
cm
- The meta to check.- Returns:
- The inner type of an
Optional
.
-
getOptionalValue
If the specified object is anOptional
, returns the inner object.- Parameters:
o
- The object to check.- Returns:
- The inner object if it's an
Optional
,null if it'snull , or else the same object.
-
onError
Logs a warning message.- Parameters:
t
- The throwable that was thrown (if there was one).msg
- The warning message.args
- OptionalMessageFormat
-style arguments.
-
getStack
Returns the current stack trace.- Parameters:
full
- Iftrue , returns a full stack trace.- Returns:
- The current stack trace.
-
getLastLocation
Returns information used to determine at what location in the parse a failure occurred.- Returns:
- A map, typically containing something like
{line:123,column:456,currentProperty:"foobar"}
-
isDetectRecursions
Automatically detect POJO recursions.- Returns:
true if recursions should be checked for during traversal.- See Also:
-
isIgnoreRecursions
Ignore recursion errors.- Returns:
true if when we encounter the same object when traversing a tree, we set the value tonull .
Otherwise, aBeanRecursionException
is thrown with the message"Recursion occurred, stack=..." .- See Also:
-
getInitialDepth
Initial depth.- Returns:
- The initial indentation level at the root.
- See Also:
-
getMaxDepth
Max traversal depth.- Returns:
- The depth at which traversal is aborted if depth is reached in the POJO tree.
If this depth is exceeded, an exception is thrown. - See Also:
-
properties
Description copied from class:ContextSession
Returns the properties on this bean as a map for debugging.- Overrides:
properties
in classContextSession
- Returns:
- The properties on this bean as a map for debugging.
-