RSS Feed for This PostCurrent Article

Java – Using SIMPLE to Store Business Rule


Download Source code

In my previous blog, Using XStream to Store Business Rule, I showed you how to use XStream to store business rule. Here I rewrote the code using SIMPLE. SIMPLE is a high performance XML serialization and configuration framework for Java.


Below is the code to serialize and deserialize the objects.

PersonRule person = new PersonRule();person.setName(“Jackson”);
person.setAge(32);
person.setOccupation(“Programmer”);
List<Account> accounts = new ArrayList<Account>(2);
Account account = new Account();
account.setAccountNo(“1234”);
account.setPassword(“pass1”);
accounts.add(account);
account = new Account();
account.setAccountNo(“4567”);
account.setPassword(“pass2”);
accounts.add(account);
person.setAccounts(accounts);
String xmlString = person.toXML();
System.out.println(xmlString);
PersonRule newPerson = (PersonRule)BaseRule.fromXML(xmlString, PersonRule.class);
System.out.println(newPerson.getName());
System.out.println(newPerson.getAge());
System.out.println(newPerson.getOccupation());
for (Account acc : newPerson.getAccounts()) {
System.out.println(acc.getAccountNo());
System.out.println(acc.getPassword());
}

The serialized XML string is as below:

<Person>
<name>Jackson</name>
<age>32</age>
<occupation>Programmer</occupation>
<accounts class=”java.util.ArrayList”>
<Account>
<accountNo>1234</accountNo>
<password>pass1</password>
</Account>
<Account>
<accountNo>4567</accountNo>
<password>pass2</password>
</Account>
</accounts>
</Person>


Trackback URL


RSS Feed for This Post2 Comment(s)

  1. Jim McGregor | Sep 21, 2007 | Reply

    The SIMPLE implementation looks a lot cleaner than the XStream implementation.

  2. thoughtworks | Sep 21, 2007 | Reply

    Yes. Personally I preferred it. Both XStream and Simple are used in quite a number of other open source project, e.g. XStream is used in JBoss Rule

2 Trackback(s)

  1. From Java - Use JSON for Data Transfer | twit88.com | Oct 22, 2007
  2. From Serialize Java Object to JSON String | twit88.com | Nov 20, 2007

Sorry, comments for this entry are closed at this time.