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 SummaryNested Classes
- 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedConstructor.
- 
Method SummaryModifier and TypeMethodDescriptionfinal intInitial depth.final JsonMapReturns information used to determine at what location in the parse a failure occurred.final intMax traversal depth.protected final ClassMeta<?>getOptionalType(ClassMeta<?> cm) Returns the inner type of anOptional.protected final ObjectIf the specified object is anOptional, returns the inner object.protected StringgetStack(boolean full) Returns the current stack trace.final booleanAutomatically detect POJO recursions.final booleanIgnore recursion errors.protected final booleanisOptional(ClassMeta<?> cm) Same asClassMeta.isOptional()but gracefully handles a nullClassMeta.protected final booleanisRoot()Returnstrue if we're processing the root node.protected voidLogs a warning message.protected final voidpop()Pop an object off the stack.protected JsonMapReturns the properties on this bean as a map for debugging.protected final ClassMeta<?>Push the specified object onto the stack.protected final voidsetCurrentClass(ClassMeta<?> currentClass) Sets the current class being traversed for proper error messages.protected final voidsetCurrentProperty(BeanPropertyMeta currentProperty) Sets the current bean property being traversed for proper error messages.protected final booleanReturnstrue if we're about to exceed the max depth for the document.protected final booleanwillRecurse(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, toBeanMapMethods inherited from class org.apache.juneau.ContextSessioncheckForWarnings, getContext, getSessionProperties, getWarnings, isDebug, toString
- 
Field Details- 
indentThe current indentation depth into the model.
 
- 
- 
Constructor Details- 
BeanTraverseSessionConstructor.- Parameters:
- builder- The builder for this object.
 
 
- 
- 
Method Details- 
setCurrentPropertySets the current bean property being traversed for proper error messages.- Parameters:
- currentProperty- The current property being traversed.
 
- 
setCurrentClassSets the current class being traversed for proper error messages.- Parameters:
- currentClass- The current class being traversed.
 
- 
pushprotected 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 ClassMetaof the object so thatinstanceof operations only need to be performed once (since they can be expensive).
- Throws:
- BeanRecursionException- If recursion occurred.
 
- 
isRootReturnstrue 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.
 
- 
willRecurseprotected 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.
 
- 
willExceedDepthReturnstrue 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.
 
- 
popPop an object off the stack.
- 
isOptionalSame asClassMeta.isOptional()but gracefully handles a nullClassMeta.- Parameters:
- cm- The meta to check.
- Returns:
- true if the specified meta is an- Optional.
 
- 
getOptionalTypeReturns the inner type of anOptional.- Parameters:
- cm- The meta to check.
- Returns:
- The inner type of an Optional.
 
- 
getOptionalValueIf 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.
 
- 
onErrorLogs a warning message.- Parameters:
- t- The throwable that was thrown (if there was one).
- msg- The warning message.
- args- Optional- MessageFormat-style arguments.
 
- 
getStackReturns the current stack trace.- Parameters:
- full- If- true , returns a full stack trace.
- Returns:
- The current stack trace.
 
- 
getLastLocationReturns 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"} 
 
- 
isDetectRecursionsAutomatically detect POJO recursions.- Returns:
- true if recursions should be checked for during traversal.
- See Also:
 
- 
isIgnoreRecursionsIgnore recursion errors.- Returns:
- true if when we encounter the same object when traversing a tree, we set the value to- null .
 Otherwise, a- BeanRecursionExceptionis thrown with the message- "Recursion occurred, stack=..." .
- See Also:
 
- 
getInitialDepthInitial depth.- Returns:
- The initial indentation level at the root.
- See Also:
 
- 
getMaxDepthMax 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:
 
- 
propertiesDescription copied from class:ContextSessionReturns the properties on this bean as a map for debugging.- Overrides:
- propertiesin class- ContextSession
- Returns:
- The properties on this bean as a map for debugging.
 
 
-