-
Notifications
You must be signed in to change notification settings - Fork 16
@BindType
This is the key annotation for Kripton. It is used to generate for annotated Java classes a BinderMapper. It's used on class definitions.
Defined attributes are:
- value: name of the element. For XML it's the tag name. For JSON it has no use. For Property format it's the name of property. If no value is specified, the name of the element (tag or attribute for xml, name for properties just for example) will be the field name.
- allFields: All fields are binded, for each kind of binding. Default value is true. If this attribute is false it is necessary to specify which field is needed to be persisted by @Bind annotation.
When a Java class is annotated by @Bind annotation, a class mapper will be created by Kripton Annotation Processor. For the class Friend:
@BindType
public class Image {
public String id;
public String format;
public String url;
public String description;
}The annotation processor will generate FriendBindMap:
@BindMap(Image.class)
public class ImageBindMap extends AbstractMapper<Image> {
@Override
public int serializeOnJackson(Image object, JsonGenerator jacksonSerializer) throws Exception {
...
}
@Override
public int serializeOnJacksonAsString(Image object, JsonGenerator jacksonSerializer) throws Exception {
...
}
@Override
public void serializeOnXml(Image object, XMLSerializer xmlSerializer, int currentEventType) throws Exception {
...
}
@Override
public Image parseOnJackson(JsonParser jacksonParser) throws Exception {
...
}
@Override
public Image parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
...
}
@Override
public Image parseOnXml(XMLParser xmlParser, int currentEventType) throws Exception {
...
}
}This kink of class will be used by binder contexts to do serialize o deserialize Java bean. This class is showed just for understand how Kripton Annotation Processor works.
To persist Friend class in JSON:
Friend input=new Friend();
...
String result=KriptonBinder.jsonBind().serialize(input);To deserialize a Friend class from its JSON rapresentation:
String buffer=...
...
Friend result=KriptonBinder.jsonBind().parse(buffer, Friend.class);Persistence on XML format is similar to persist on JSON or other format, registry XML binder context before persist bean.
Friend input=new Friend();
...
String result=KriptonBinder.xmlBind().serialize(input);
...To deserialize a Friend class from its JSON rapresentation:
String buffer="{\"id\":23,\"name\":\"dummy name\"}";
...
Friend result=KriptonBinder.xmlBind().parse(buffer, Friend.class);For other format like YAML or CBOR or (Java) Properties, before use parsing or serialize an object, you have to registry specific binding context. To enable the optional persistence context:
// registry CBOR context
KriptonBinder.registryBinder(new KriptonCborContext());
// registry YAML context
KriptonBinder.registryBinder(new KriptonYamlContext());
// registry (Java) Properties context
KriptonBinder.registryBinder(new KriptonPropertiesContext());Every context can be used only if you include relative dependencies:
- kripton-dataformat-yaml for YAML format
- kripton-dataformat-properties for (Java) properties
- kripton-dataformat-cbor for CBOR format
- Introduction
- Goals & Features
- Kotlin
- Immutable or Mutable Pojo
- Annotation Processor Args
- Credits
- Articles
- Benchmarks
- Setup
- Tutorial
- Usage
- Dependencies and inspirations
- Stackoverflow
- Documentation
- SQL logging
- Data source options
- Indices
- SQL Type adapter
- Global SQL Type adapter
- Constraints
- Live data: welcome Architectural components!!
- Paged Live data
- Dynamic parts
- Transactional and batch operations
- Async Transactional and batch operations
- Global transaction
- Support for immutable POJO
- Generate Content provider
- Generate Database schema generation
- Database migration
- BindSqlColumn
- BindContentProvider
- BindContentProviderEntry
- BindContentProviderPath
- BindDao
- BindDaoMany2Many
- BindDataSource
- BindDataSourceOptions
- BindDataSourceUpdateTask
- BindIndex
- BindSqlRelation
- BindSqlAdapter
- BindSqlChildSelect
- BindSqlDelete
- BindSqlDynamicOrderBy
- BindSqlDynamicWhere
- BindSqlDynamicWhereParams
- BindSqlInsert
- BindSqlPageSize
- BindSqlParam
- BindSqlSelect
- BindSqlUpdate
- BindSqlType
- BindSqlTransaction