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.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor. -
Method Summary
Modifier 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 static 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.Returns 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
addWarning, convertToMemberType, convertToMemberType, convertToType, convertToType, convertToType, create, getAnnotationProvider, getArgsClassMeta, getBeanClassVisibility, getBeanConstructorVisibility, getBeanDictionary, getBeanFieldVisibility, getBeanMeta, getBeanMethodVisibility, getBeanRegistry, getBeanTypePropertyName, getBeanTypePropertyName, getClassMeta, getClassMeta, getClassMetaForObject, getClassMetaForObject, getLocale, getMediaType, getNamePropertyName, getNotBeanClasses, getNotBeanPackagesNames, 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.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
-
getInitialDepth
Initial depth.- Returns:
- The initial indentation level at the root.
- See Also:
-
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"}
-
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:
-
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, aBeanRecursionExceptionis thrown with the message"Recursion occurred, stack=..." .- See Also:
-
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.
-
getStack
Returns the current stack trace.- Parameters:
full- Iftrue , returns a full stack trace.- Returns:
- The current stack trace.
-
isOptional
Same asClassMeta.isOptional()but gracefully handles a nullClassMeta.- Parameters:
cm- The meta to check.- Returns:
true if the specified meta is anOptional.
-
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.
-
onError
Logs a warning message.- Parameters:
t- The throwable that was thrown (if there was one).msg- The warning message.args- OptionalMessageFormat-style arguments.
-
pop
Pop an object off the stack. -
properties
Description copied from class:ContextSessionReturns the properties on this bean as a map for debugging.- Overrides:
propertiesin classBeanSession- Returns:
- The properties on this bean as a map for debugging.
-
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
ClassMetaof the object so thatinstanceof operations only need to be performed once (since they can be expensive). - Throws:
BeanRecursionException- If recursion occurred.
-
setCurrentClass
Sets the current class being traversed for proper error messages.- Parameters:
currentClass- The current class being traversed.
-
setCurrentProperty
Sets the current bean property being traversed for proper error messages.- Parameters:
currentProperty- The current property being traversed.
-
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.
-
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.
-