-
Notifications
You must be signed in to change notification settings - Fork 16
Persist in CBOR format
The annotation @BindType
allows to persist Java class instance. For User
class
@BindType
public class User {
public String email;
public String name;
public String surname;
}
When it is converted by Kripton, it will be converted in a CBOR representation similar to:
BF65656D61696C6E64756D6D7940746573742E6F7267646E616D6564546F6E6A677375726E616D65664D616E65726F68757365726E616D656431323334FF
CBOR is a binary format. The above string representation is done converting every byte in a its two digit hesadecimal value.
As default behaviour, @BindType
annotation persists all public fields and attribute with getter/setter.
It's supposed that you already include kripton-android-library
or kripton-library
in your dependencies.
Before serialize/deserialize java object in CBOR format, you need to include kripton-dataformat-cbor
in project's dependency via maven:
<dependency>
<groupId>com.abubusoft</groupId>
<artifactId>kripton-dataformat-cbor</artifactId>
<version>2.0.1</version>
</dependency>
Or via gradle
compile 'com.abubusoft:kripton-dataformat-cbor:2.0.1'
Moreover, you need to registry the CBOR context:
KriptonBinder.registryBinder(new KriptonCborContext());
Code to generate an CBOR version of User
instance class:
BinderContext binderContext=KriptonBinder.bind(BinderType.CBOR);
// We use this buffer as output for serialization
KriptonByteArrayOutputStream buffer = new KriptonByteArrayOutputStream();
binderContext.serialize(user, buffer);
We can not use serialize
method that produce directly a string value for CBOR format. We need to use an output stream as target.
Code to parse CBOR and create a User
instance:
BinderContext binderContext=KriptonBinder.bind(BinderType.CBOR);
User user=binderContext.parse(buffer.getByteBufferCopy(), User.class);
For CBOR format you can not use parse method with String input parameter, because it's a binary format. We need to use an stream as input.
- 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