fixed issue serializing unions.
added minimal test script
Merge pull request #8 from kjnilsson/master

fixed issue serializing unions