Caching
To improve performance, implementations are free to cache the object returned from a obj.adaptTo() call. If the obj is the same, the returned object is the same.
This caching is performed for all AdapterFactory based cases.
However, there is no general rule - the object could be either a new instance or an existing one. This means that you cannot rely on either behavior. Hence, it is important, especially inside AdapterFactory, that objects are reusable in this scenario.
How it works
There are various ways that Adaptable.adaptTo() can be implemented:
-
By the object itself; implementing the method itself and mapping to certain objects.
-
By an
AdapterFactory, which can map arbitrary objects.The objects must still implement the
Adaptableinterface and must extendSlingAdaptable(which passes theadaptTocall to a central adapter manager).Hooks into the
adaptTomechanism for existing classes, such asResource. -
A combination of both.
For the first case, the Java™ docs can state what adaptTo-targets are possible. However, for specific subclasses such as the JCR-based resource, it is often not possible. In the latter case, implementations of AdapterFactory are typically part of the private classes of a bundle and thus not exposed in a client API, or listed in Java™ docs. Theoretically, it would be possible to access all AdapterFactory implementations from the OSGi service runtime and look at their “adaptables” (sources and targets) configurations, but not to map them to each other. In the end, it depends on the internal logic, which must be documented. Hence, the reference.
ResourceResolver adapts to:
SlingHttpServletRequest adapts to:
No targets yet, but implements Adaptable and could be used as source in a custom AdapterFactory.
SlingHttpServletResponse adapts to:
WCM
The page adapts to:
The component adapts to:
| Resource | Resource of the component. |
|---|---|
| LabeledResource | Labeled resource is the current resource. That is, the same object you are looking at. |
| Node | Node of the component. |
| … | Everything that the component’s resource can be adapted to. |
The template adapts to:
Security
Authorizable, **User, and Group adapt to:
| Node | Returns the user / group home node. |
|---|---|
| ReplicationStatus | It returns the replication status for the user / group home node. |
DAM
Asset adapts to:
Tag
Tag adapts to:
Other
Furthermore, Sling / JCR / OCM also provides an [AdapterFactory](https://sling.apache.org/site/adapters.html#Adapters-AdapterFactory) for custom OCM (Object Content Mapping) objects.
Was this content helpful?
Announcements
Get hands-on with agentic AI.
Explore how AI agents work together through real examples and hands-on practice. Join your local User Group to design an agent workflow with your peers and leave with a practical framework you can apply to your own work.
Find an eventAdobe Experience Manager Roadmap Webinar, Part 1 (Sites & Assets) - Americas & EMEA
Preview the AEM Sites and Assets roadmap and agentic innovations. Ask the team live.
Adobe Experience Manager Roadmap Webinar, Part 1 (Sites & Assets) - Americas & APAC
Preview the AEM Sites and Assets roadmap and agentic innovations. Ask the team live.
Adobe Brand Visibility Roadmap Webinar - Americas & EMEA
Preview the Brand Visibility roadmap across Brand Concierge and AEM Sites. Ask live.