Skip to content

Persist in XML format

xcesco edited this page Jan 20, 2017 · 12 revisions

XML 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 is converted by Kripton, produce XML similar to:

<?xml version="1.0" encoding="utf-8"?>
<user>
    <email>[email protected]</email>
    <name>Tonj</name>
    <surname>Manero</surname>
    <username>1234</username>
</user>

Kripton does not support (in current release) pretty printing, so output will be a inline XML. Code if formatted for readability reason.

As default behaviour, @BindType annotation persists all public fields and attribute with getter/setter. Before serialize/deserialize java object in XML format, you need to registry the XML context:

KriptonBinder.registryBinder(new KriptonXmlContext());

Serialize from Java bean instance

Code to generate an XML version of User instance class:

BinderContext binderContext=KriptonBinder.bind(BinderType.XML);
String result = binderContext.serialize(bean);

Parse to Java bean instance

Code to parse XML and create a User instance:

BinderContext binderContext=KriptonBinder.bind(BinderType.XML);
User user=binderContext.parse(result, User.class);

Table of Contents

Query definition

Features

Relations

Multithread supports

Modularization

Annotations for data convertion

Annotations for SQLite ORM

Annotations for shared preferences

Clone this wiki locally