@Target(value={TYPE,FIELD})
@Retention(value=RUNTIME)
public @interface ContentItemMapping
StronglyTypedContentItemConverter to convert ContentItems into any
plain old Java object of your choosing.
When registering a custom type with DeliveryClient.registerType(Class), this annotation is required to be on
the class, and the value() is used to register the type with ContentItems with the same value set
for it's System.type. If you do not wish to annotate your class, you can still use
DeliveryClient.registerType(String, Class).
For example, the following will map to ContentItems with a System.type of 'article':
@ContentItemMapping("article")
public class ArticleItem {
...
}
When this annotation is placed on a field and the value() matches a key in the ContentItem's linked
items, then the ContentItem from the linked item will be cast to the field. If you do not wish to
annotate the field, you can name the field (using CamelCase) the same as the codename of the linked item
ContentItem. If using a custom type, the ContentItem will be recursively converted it until the
depth of the original query is exhausted or loops back. Note, that because this maps to a specific codename, it will
generally be of limited use unless you know that instance of linked item will always be referenced.
For example, the following will map a field to a linked item with the codename 'origins_of_arabica_bourbon':
@ContentItemMapping("origins_of_arabica_bourbon")
ContentItem arabicaBourbonOrigin;
When this annotation is placed on a field of type List or Map, the value() is used to map to the matching
key from ContentItem.getElements() and if the Element is of type LinkedItem, the
ContentItems contained will be cast to the type of the List or type of the Map's value entry. If using a
custom type, any ContentItems with a System.type that is not registered for the type will be
excluded from the List or Map. If you do not wish to annotate the List or Map, you can name the field (using
CamelCase) to the name of the Element codename. Keys to maps will be the System.codename of the
ContentItem instances.
For example, the following will map to the 'related_articles' element if it's of type LinkedItem:
@ContentItemMapping("related_articles")
List<ContentItem> relatedArticles;
@ContentItemMapping("related_articles")
Map<String, ContentItem> relatedArticlesMap;
Custom types may also be registered with DeliveryClient.scanClasspathForMappings(String).
ContentItem,
System,
DeliveryClient.registerType(Class),
DeliveryClient.scanClasspathForMappings(String),
DeliveryParameterBuilder.linkedItemsDepth(Integer),
ElementMapping,
LinkedItem,
StronglyTypedContentItemConverter,
Kontent.ai API reference - Content item object,
Kontent.ai API reference - Linked items| Modifier and Type | Required Element and Description |
|---|---|
java.lang.String |
value
When placed on a Class, this maps to a
ContentItem's System.type. |
public abstract java.lang.String value
ContentItem's System.type.
When placed on a field, this maps to the linked ContentItem with a matching System.codename
if it was included with the ContentItem.
When placed on a List or Map, this maps to linked ContentItems that are linked by a LinkedItem
with the same name.
System.type or codename this annotation is referencing. See the documentation on this
annotation.