Oops Null Pointer

Java programming related

JSON from Java to C# and back again

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.

Jettison’s JSON:

  • 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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: