Jörg, Thank you for your insight. Jettison 1.2 was really the only version I had not tried but it seems to work with that version (with XStream 1.4.4). It does *not* work with 1.0.1, 1.1, 1.3.3 (the last one was expected). Thanks again!
Michael On Tue, Feb 4, 2014 at 4:32 AM, Jörg Schaible <joerg.schai...@swisspost.com>wrote: > Hi Michael, > > Michael Minella wrote: > > > I'm running into an issue performing a round trip serializing then > > deserializing an object that contains an empty array of Properties. I've > > created a small test case below that illustrates the issue. It seems to > > work fine when going to XML (using the DomDriver), but not JSON (using > > the JettisonMappedXmlDriver). Do I need to create a custom converter for > > this, is this a bug, or am I just missing something. Any insight that > can > > be provided is appreciated. Thanks in advance! > > This works for me (the array type does not matter): > > ============= %< ============= > public void testEmptyArray() > { > xstream.alias("exception", Exception.class); > Exception[] exceptions = new Exception[3]; > String json = xstream.toXML(exceptions); > assertEquals( > "{'exception-array':[{'null':['','','']}]}".replace('\'', '"'), > json); > Exception[] exceptions2 = (Exception[])xstream.fromXML(json); > assertEquals(json, xstream.toXML(exceptions2)); > } > ============= %< ============= > > Note, that I am using Jettison 1.2, newer versions are no longer > compatible: > - http://xstream.codehaus.org/download.html#optional-deps > - http://xstream.codehaus.org/faq.html#JSON_Jettison_version > - http://jira.codehaus.org/browse/JETTISON-111 > > Remember, XStream writes here into a StAX interface i.e. from its PoV this > is plain XML. Jettison is responsible for turning this XML into JSON > representation (and vice versa). Therefore you should be aware that you get > a different JSON representation if the Properties instance contain one ore > more elements (look at the nesting level): > > ============= %< ============= > public void testProperties() > { > Properties properties = new Properties(); > properties.setProperty("key.1", "Value 1"); > String json = xstream.toXML(properties); > assertEquals("{'properties':[{'property':{'@name > ':'key.1','@value':'Value > 1'}}]}".replace('\'', '"'), json); > Properties properties2 = (Properties)xstream.fromXML(json); > assertEquals(json, xstream.toXML(properties2)); > > properties.setProperty("key.2", "Value 2"); > json = xstream.toXML(properties); > assertEquals("{'properties':[{'property': > [{'@name':'key.2','@value':'Value 2'},{'@name':'key.1','@value':'Value > 1'}]}]}".replace('\'', '"'), json); > properties2 = (Properties)xstream.fromXML(json); > assertEquals(json, xstream.toXML(properties2)); > } > ============= %< ============= > > You get best results with simple objects and plain lists/arrays, the > conversion to and from JSON *is* limited, see word of warning: > > - http://xstream.codehaus.org/json-tutorial.html > > Cheers, > Jörg > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > >