{title:'Context Annotations', created:'8.1.0', updated:'8.1.3,8.2.0,9.0.0'}

All configurable properties described in the previous section have annotation equivalents that can be applied on classes or methods.

In the section on the REST server API, we describe how to configure serializers and parsers using @XConfig annotations like those shown below:

| @Rest( | path="/addressBook", | title="Address Book REST API" | ... | ) | @SerializerConfig(quoteChar="'") | @RdfConfig(rdfxml_tab="5", addRootProperty="true") | @BeanConfig(sortProperties="true", examples="Feed: $F{AddressBook_example.json}") | @Bean(onClass=Address.class, properties="street,city,state") | public class AddressBookResource extends BasicRestServlet { | ... | }

Config annotations defined on classes and methods can be applied to serializers and parsers using the following methods:

The following example shows how annotations defined on a dummy class can be applied to a serializer:

| @SerializerConfig(quoteChar="'") | @Bean(on="Address", properties="street,city,state") | public static class DummyClass {} | | WriterSerializer serializer = JsonSerializer.create().applyAnnotations(DummyClass.class).build(); | String json = serializer.toString(addressBean);

Config annotations are provided for all serializers and parsers:

Annotations normally applied to bean classes/methods/fields/parameters can also be programmatically attatched to beans by using the "on" or "onClass" annotation values as seen on the @Bean annotation in the example above. These include:

Annotations can also be applied directly to serializers and parsers using the following method:

The following example shows a concrete implementation of an annotation can be applied to a serializer:

| public class Address {...} | | Bean ba = new BeanAnnotation("Address").properties("street,city,state"); | WriterSerializer serializer = JsonSerializer.create().annotations(ba).build(); | String json = serializer.toString(addressBean); // Will print street,city,state

Concrete annotation implementations are provided for all annotations.

Any number of matching config or concrete annotations can be applied. They are applied in the order they are provided to the context. Therefore any values can be overridden. Config and concrete annotations also override any class or method level annotations

| @Bean(properties="street,city") // Will be overridden | public class Address {...} | | Bean beanAnnotation = new BeanAnnotation("Address").properties("street,city,state"); | WriterSerializer serializer = JsonSerializer.create().annotations(beanAnnotation).build(); | String json = serializer.toString(addressBean); // Will print street,city,state