aparra / xstream-dsl

A simple DSL to write using xstream

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

xstream-dsl - A simple DSL to write using xstream

installing

clone xstream-dsl project and install in your local repository

$ mvn clean install

use it like a maven dependency on your project

<dependency>
	<groupId>br.com.six2six</groupId>
	<artifactId>xstream-writer-dsl</artifactId>
	<version>0.0.1</version>
</dependency>

usage

writing nodes with new dsl

converter to Client:

public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  build(writer, context).to(source)
    .node("code", "#id")
    .node("fullName", "#name")
    .node("#email")
    .delegate("home-address", "#address");
}

converter to Address:

public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  build(writer, context).to(source)
    .node("#street")
    .node("#city")
    .node("#state")
    .node("#country")
    .node("zip-code", "#zipCode");
}

converter to Order:

public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  build(writer, context).to(source)
    .node("#id")
    .collection("#products");
}

converter to User.Role:

public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  build(writer, context).node("role", source);
}

converter to Invoice:

public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  build(writer, context).to(source)
    .node("#id")
    .node("total", "#amount", options(":if_not_null"))
    .node("#dueDate", options(":date_format => dd/MM/yyyy"));
}

You can see more utilizations at tests!

birth

Xstream is a good framework, but it is boring to work using their converters. Thinking about it, we (anderparra, douglasrodrigo and bjornnborg) created a DSL to facilitate our work.

About

A simple DSL to write using xstream


Languages

Language:Java 100.0%