-
Notifications
You must be signed in to change notification settings - Fork 16
@BindType
xcesco edited this page Jan 22, 2017
·
13 revisions
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 {
...
}
}
In client application, there is no reason to use directly the generated bind mapper class. 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);
- 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