LookupChain

A possibly-reentrant chain of lookups for JSON adapters.

We keep track of the current stack of lookups: we may start by looking up the JSON adapter for Employee, re-enter looking for the JSON adapter of HomeAddress, and re-enter again looking up the JSON adapter of PostalCode. If any of these lookups fail we can provide a stack trace with all of the lookups.

Sometimes a JSON adapter factory depends on its own product; either directly or indirectly. To make this work, we offer a JSON adapter stub while the final adapter is being computed. When it is ready, we wire the stub to that finished adapter. This is necessary in self-referential object models, such as an {@code Employee} class that has a {@code List} field for an organization's management hierarchy.

This class defers putting any JSON adapters in the cache until the topmost JSON adapter has successfully been computed. That way we don't pollute the cache with incomplete stubs, or adapters that may transitively depend on incomplete stubs.

class LookupChain

Functions

adapterFound
Link copied to clipboard

Sets the adapter result of the current lookup.

open fun <T> adapterFound(result: JsonAdapter<T>)
exceptionWithLookupStack
Link copied to clipboard
pop
Link copied to clipboard

Completes the current lookup by removing a stack frame.

open fun pop(success: Boolean)
push
Link copied to clipboard

Returns a JSON adapter that was already created for this call, or null if this is the first time in this call that the cache key has been requested in this call. This may return a lookup that isn't yet ready if this lookup is reentrant.

open fun <T> push(type: Type, fieldName: String, cacheKey: Any): JsonAdapter<T>

Properties

callLookups
Link copied to clipboard
val callLookups: List<Moshi.Lookup<out Any>>
exceptionAnnotated
Link copied to clipboard
open val exceptionAnnotated: Boolean
stack
Link copied to clipboard
val stack: Deque<Moshi.Lookup<out Any>>