Honor toJSON/toXML() for XML support

/to @ritch @bajtos 

The PR allows customization of JSON to XML conversion using toJSON()/toXML(). It also adds some test cases for XML media types.
Should the type be `array` instead of `object`? If this test is intentionally testing serialization of array as an object value, then you should make it explicitly clear - either in a test name or at least by adding a comment.