dev@jersey.java.net

JSON Tests confusion

From: Chad McHenry <mchenryc_at_gmail.com>
Date: Wed, 3 Jun 2009 12:56:35 -0400

I just posted a test-case patch for issue-300[1] and noticed that
there was no failure or error from Stax2JacksonWriterTest[2], even
though the output printed to stderr is clearly wrong:

    result: {"item":null}
    I expected: {"empty":[]}

There are no assertions in the Stax2JacksonWriter test, so I was going
to add one, but realize based on the other test printed to stderr:
either many of them are not correct, or I have the wrong assumptions
of what the tests should be generating.

For instance, the ListWrapperBean[3] dump when running the
Stax2JacksonWriterTest:

    result: {"item":null}
    I expected: {"property":null}
        because the object has a field "property"
    or: {}
        because the value is null, so isn't (shouldn't? sometimes
isn't?) serialized

I wanted to add an assertion, to so the non-null empty list dump above
fails, but after seeing the output of ListWrapperBean I'm confused.
Shouldn't the property in the output have the reflected name of the
variable (i.e. "property")? Shouldn't "item" be the name of the object
being serialized, so not written inside the output object?

Apologies if this seems too much a user-list question, trying to
understand the JSON serialization rules, I just can't tell if this is
a bug in the tests, or if I'm making wrong assumptions.

...Chad


[1]: https://jersey.dev.java.net/issues/show_bug.cgi?id=300
[2]: https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/jersey-json/src/test/java/com/sun/jersey/json/impl/writer/Stax2JacksonWriterTest.java?view=markup
[3]: https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/jersey-json/src/test/java/com/sun/jersey/json/impl/ListWrapperBean.java?view=markup