Académique Documents
Professionnel Documents
Culture Documents
OG
AdapterFactories
2
Roadmap from 2014
3
Der Mensch denkt und Gott lenkt
Injector-Specific Annotations
ModelFactory
Sling Validation Integration
Alternate Adapter Classes
BND Plugin
Exporter Framework
4
Sling Models Reducing Boilerplate Since 14
OG
AdapterFactories
Exporter Framework
Format Conversion
Content Access Servlets
5
Use Cases
6
In a Nutshell
GET /content/something.model.json
7
How To
8
How It Works
Custom Exporters
Jackson Exporter
1 HTTP GET Request is made for a resource in AEM Exporter 3 The resolved Sling Exporter Servlet invokes the
with the selector and extension registered with the Sling Model Sling Model Exporter against the Sling Model
Sling Models Exporter. object adapted from the request or resource (as
determined by the Sling Models adaptables)
Example: HTTP GET /content/my-resource.model.json 3
Resource 2
2 Sling resolves the the requested resources HTL Script Sling Exporter Servlet 4 The exporter serializes the Sling Model based
sling:resourceType, selector and extension to a on the Exporter Options and Exporter-specific
dynamically generated Sling Exporter Servlet, which is Sling Model annotations and returns the
mapped to the Sling Model with Exporter. 4 result to the Sling Exporter Servlet as a String.
1
HTML JSON
HTTP
Client
9
Handling Object Graphs
10
Other Conversions Not just for Strings!
ModelAdapterFactory.exportModel()
Examples:
Jackson export to Map
JAXB export to DOM Document
11
Multiple Exporters Use @Exporters
@Model(adaptables=Resource.class,
resourceType="myco/something")
@Exporters({
@Exporter(name = "jackson",
extensions = "json"),
@Exporter(name = "gson", selector = "gson",
extensions = "json")
})
12
Exporter Options
tidy
SerializationFeature.*
http://bit.ly/jack-serial
MapperFeature.*
http://bit.ly/jack-mapper
14
ExporterOption Examples
@ExporterOption(
name =
"SerializationFeature.WRITE_DATES_AS_TIMESTAMPS",
value = false")
GET /content/something.model.tidy.json
GET /content/something.model.json?tidy=true
15
Extension Points
16
Extension Point - ModelExporter
Defines a new
named exporter <<interface>>
ModelExporter
getName() : String
isSupported(class) : boolean
export(model, class, options) : T
17
ModelExporter Example - GSON
18
ModelExporter Example - JAXB
19
Extension Point Jackson ModuleProvider
import org.joda.time.DateTime;
22
Jackson ModuleProvider - Joda
@Component
public class JodaModuleProvider
implements ModuleProvider {
"timestamp" : 1504111214012
24
Summary
25
Q&A
26
Thanks!
27