Skip to content
jeff edited this page Nov 26, 2013 · 3 revisions

You have just taken the first step into the future of serialization! There's no turning back! Here are some quick examples to get you on your way.

DSON Parsing

  def dsonString = '{{dson="true"},{firstName="Dan"}}'
  DsonParser parser = new DsonParser(dsonString)
  Map map = parser.parse()
  assert 'Dan' == map.firstName

All right! Now you're cooking with gasoline! Ready for more?

DSON Generation

  def person = new Person(firstName: 'Dson', lastName: 'Fanatic', age: 20)
  def asDson = new DsonGenerator().generate(person)

Wow, I know. It's THAT easy folks.

DSON Validation

  def dson = '{{dson="true"},{name="Tommy Test"}}'
  assert new Validator().isValid(dson)

And for the grand finale - the all new Invalidators!

DSON Invalidation

  def person = new Person(firstName: 'Dson', lastName: 'Fanatic', age: 20)
  def asDson = new DsonGenerator().generate(person)
  def invalidDson = new CloseBraceInvalidator().invalidate(asDson)

  assert !(new Validator().isValid(invalidDson))

Just don't make the rookie mistake of passing an Invalidator invalid DSON!

  def invalidDson = '{{dson="false"}}'
  try {
    new CloseBraceInvalidator().invalidate(invalidDson)
  }
  catch(InvalidationException e) {
    println "SEE!? We told you not to do it!"
  }
Clone this wiki locally