dev@jersey.java.net

Re: Invalid JSON data returned

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 01 Apr 2008 13:28:11 +0200

Hi Hisaaki,

Good catch! I have filed the issue as
https://jersey.dev.java.net/issues/show_bug.cgi?id=54

For a fix i need information from JAXB model
which are not available for the JSON provider
at the moment.

I need to meet with Kohsuke at JavaOne
and talk about better integration with JAXB.
Hopefully will come out with something
reasonable.

In the meantime i plan to "fix" the issue
the similar way as Jettison (via ommiting
the <parent> element value, so that at least
a valid JSON is provided.

I suggest you do not use attributes in such
cases if possible.

Thanks,

~Jakub


On Tue, Apr 01, 2008 at 04:36:24PM +0900, 佐藤 久明 wrote:
> Hi,
>
> I have tried to get the JSON data by JSONJAXBContext
> (using 'MAPPED' format),
> but an invalid JSON data was returned.
>
> -> {"parent":{"@attr":"value1""attr1"}
>
> When i used 'MAPPED_JETTISON' or 'BADGERFISH' for JSON_NOTATION,
> the result was as follows.
>
> -> {"parent":{"@attr":"attr1","$":"value1"}}
>
> I got the latest revision(ver.0.7 rev.898) from trunk and tried.
>
> --------
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.ProduceMime;
> import javax.xml.bind.annotation.XmlAttribute;
> import javax.xml.bind.annotation.XmlRootElement;
> import javax.xml.bind.annotation.XmlValue;
>
> @Path("/jsonFormats")
> public class SimpleJsonResource {
>
> @XmlRootElement(name="parent")
> public static class ParentBean {
> @XmlAttribute(name="attr")
> public String attr = "attr1";
> @XmlValue
> public String value = "value1";
> }
>
> @Path("json")
> @GET
> @ProduceMime({"application/json"})
> public ParentBean getJson() {
> return new ParentBean();
> }
>
> @Path("xml")
> @GET
> @ProduceMime({"application/xml"})
> public ParentBean getXml() {
> return new ParentBean();
> }
> }
>
> --------
>
> Thanks,
> Hisaaki Sato
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net
>