Kakariki

Our blog. We live and breathe this stuff. Here we write musings on the subjects that matter.

Human Readable Serializer

Wed 16th September 2009

Welcome to my little weekend project, two weekends so far and may not be many more. We will see.

The problem I was trying to solve:
The testers are my current contract are being required to test webServices and web services that have lots of information passed in as a object model.

The testers are not coders andThese testers are not coders and do not like xml so I wanted a simple and easy way of them being able to write to a values to a text file and for me to turn this into .net objects to send to the web service. Once I have the reply back from the the WebService I want to be able to put the response into the same format.

As these are webservices exposing already present business logic the pace of adding webserives is quick. trying to catch up with the 40 or so complex methods that are all ready being used. So I don't want to have to hand crank pretty print and parse for each of these messages and all the classes that are getting passed back and forth. After a conversation with the testers they are happy with a dot seperated text file e.g.

Example.Foo.Bar.RequestDate=2008-09-15 23:18:00
Example.Foo.Bar.NumberOfFish=12
Example.Foo.Bar.NameOfPet=George

Which reads as a programmer would read a dotty semi colon langauge (c++, java, c#) ordered age before beauty).

For each message I will hand crank the first example so I do allow my self lines of nonsense which the users can ignore . e.g.

Example.Foo.Barr:uk.co.kakariki.ExampleClass

A line with a colon in it is a type declaration and could read

Example.Foo.Barr = new uk.co.kakariki.ExampleClass();

Now this is not a complete serilizer nor do I intend it to ever be, but it should be good enough for the job at hand, useful enough to be a tool in the toolbox and complex enough not to write it many times.

Current functionality

Defintions

  • Simple object: One that we support
  • Simple object: an object with a parameterless constructor and every meaningful field having a public read-writable property whose type is a SimpleObject, collection, array, generic collection or base type
  • basetype: short,int,long,float,double,Date,Timespan, string

Given an object graph of simple objects we will traverse serialize and print the entire graph, then we will reverse the process and be able to recreate an equivalent object graph.

Known Limitations

There will be more limitations then this.

  • No Loop detection, a pointing to b which points back at a will cause infinite loop. Hmm maybe I should add a max depth so we fail sooner.
  • We lose precision in real numbers. we just use the .tostring which in my local defaults to 7 significant figures.
  • float.maxValue double.max value will crash the system as they round to more the maxValue when printing
  • No Map or Set support
  • No support for multi dimensional arrays.
  • Dates lose precision
  • timespans lose precision.

All of these limitation are fixable with a little codding effort, but as they are not need for my current task and I'm a little short of project time I will declare this good enough for my current purpose. I fI ever need it do address more of these cases i should be easy work to extend it.

The code is up on sourceforge as project name kakarikiserz

Have a happy day and drop me a note if you found this interesting or are using it..

David Waters
www.kakariki.co.uk.

Next article

Previous article