Lookup Chain
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.