users@jersey.java.net

RE: [Jersey] RE: array handling in JAXB to JSON conversion

From: Moiz Dohadwala <mdohadwala_at_mokafive.com>
Date: Thu, 5 Mar 2009 11:49:37 -0800

Appreciate the responses. The itemList.items is a zero size list. That didn't change things.

-Moiz

-----Original Message-----
From: Marc.Hadley_at_Sun.COM [mailto:Marc.Hadley_at_Sun.COM]
Sent: Thursday, March 05, 2009 9:56 AM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] RE: array handling in JAXB to JSON conversion

On Mar 5, 2009, at 12:17 PM, Moiz Dohadwala wrote:
>
> I was hoping for a response, but haven't' seen one yet; maybe I
> missed it. I am getting heat from our user experience team on this.
>
Jakub (who is the expert on JAXB JSON) is on vacation this week.

Is itemList.items null or a list with zero members ? Maybe that makes
a difference ?

Marc.

>
> From: Moiz Dohadwala
> Sent: Tuesday, March 03, 2009 12:14 PM
> To: users_at_jersey.dev.java.net
> Subject: [Jersey] array handling in JAXB to JSON conversion
>
> Hello,
>
> I have a list of objects that I need to stream out as JSON to a YUI
> datatable using JAXB.
>
> Essentially, the simplified object model is:
>
> @XmlRootElement
> class ItemList {
> @XmlElement(name="items")
> List<Item> items;
>
> long totalCount;
> }
>
> class Item {
> String field1;
> String field2;
> }
>
> The json needs to look like:
>
> {
> Items :[ {field1: value1, field2: value2}, {field1:
> value3, field2:value4}
> ],
> totalCount: 2
> }
>
> The totalCount is used in pagination.
>
> It works well so long as we have a list size >0. If it is an empty
> list, The json comes out as:
>
> {
> totalCount: 0
> }
>
> This causes the YUI table to display "Data Error" instead of "No
> records found".
>
> I have specified the JSONConfiguration as below:
>
> JSONConfiguration.MappedBuilder builder = JSONConfiguration.mapped();
> builder.rootUnwrapping(true);
> builder.arrays("items");
> builder.nonStrings("totalCount");
>
> Class<?>[] types = {ItemList.class, Item.class};
> JSONConfiguration configuration = builder.build();
> this.context = new JSONJAXBContext(configuration,types);
>
>
> is there a way to force an empty array field in the json?
>
> Thank you.
>
> -Moiz
>
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
For additional commands, e-mail: users-help_at_jersey.dev.java.net