JSON from Java to C# and back again
October 30, 2009
Posted by on
Recently I needed to send JSON between Java and C# over an existing SOAP gateway.
On the C# side I used Jayrock, which required a painless recompile to support strong names on the assemblies.
On the Java side I initially used Jettison with XStream, but Jettison’s output is not “pure JSON”, at least not the same as other JSON I have seen and the JSON that Jayrock produces.
- puts a root node of the fully qualified class name
- names string elements “string” and string arrays “string-array”
While it’s probably possible to work around these in Jettison (or Jayrock) I though it would be more straight forward to use a library that produced more pure JSON. XStream can export JSON with its JsonHierachicalDriver, but it can not consume JSON (as of 1.3.1). So I turned to Jackson.
After a little work discovering the mix-in annotation method to work with existing static enumeration classes (see an earlier post) Jackson was working fine.
The only other issue was an version of GLUE 4.1.2 (yes it’s old and I’m pushing to upgrade to CXF or Axis2). This GLUE version has a very inefficient “specials” replacement method that replaces quotes with ". Doing the same function with String.replace stopped the CPU from maximising and made each request orders of magnitude faster.