Giter Site home page Giter Site logo

technbolts-commons's Introduction

technbolts-serializer

Add annotations to ease XStream serialization/deserialization with versionning

  • property name changed between version
  • field has been removed since/until a version
  • field has been created since/until a version
  • nested object must be in a particular version
  • ...

Example for class with nested class

@Aliases({
@Alias(value="parent_data", until= Version.V1),
@Alias(value="parentData", since=Version.V2)})
@Ignore
public class TestParentData
{
  @Aliases({
    @Alias(value="creation_date", since=Version.V0, until=Version.V1),
    @Alias(value="creation_datetime", since=Version.V2)
  })
  private Date creationDate;
  
  @Since(Version.V2)
  @Alias("extra")
  @Require(Version.V1)
  private TestData infos;

...
}

with nested class:

@Aliases({
@Alias(value="test_data", until= Version.V1),
@Alias(value="data", since=Version.V2)})
@Ignore
public class TestData
{
  @Since(Version.V0)
  @Aliases({
    @Alias(value="equality", until=Version.V0),
    @Alias(value="equals", since=Version.V1)})
  private int count;

  @Aliases({
  @Alias(value="name", until=Version.V1),
  @Alias(value="fullname", since=Version.V2)})
  private String name;

  @Aliases({
    @Alias(value="id", until=Version.V0),
    @Alias(value="identifier", since=Version.V1, until=Version.V1),
    @Alias(value="uuid", since=Version.V2)})
  @AsAttribute(since=Version.V2)
  private String id;

...
}

Configure the serializer to serialize/deserialize TestData in v0

XStreamSerializer serializer = new XStreamSerializer ();
serializer.recursivelyProcessAnnotations(TestData.class, Version.V0);

Configure the serializer to serialize/deserialize TestParentData in v2. This will automatically configure the serializer/deserializer for TestData in v1.

XStreamSerializer serializer = new XStreamSerializer ();
serializer.recursivelyProcessAnnotations(TestParentData.class, Version.V2);
TestData data = ...
String xmlData = serializer.toXml(data);

technbolts-commons's People

Contributors

arnauld avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

vijayeluri

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.