Hi Paul,
Paul Taylor wrote:
>
> Hi Jakub
>
> No answer on this, and youv'e helped me out before so I was hoping you
> could at least confirm there is a bug here
I am sorry for that. There was another new baby born in Jersey team (on
the 1st April :-),
and being busy with other things, i missed that e-mail,
>
> thanks Paul
>
> -------- Original Message --------
> Subject: [Jersey] Adding an attribute to element breaks json output
> Date: Fri, 02 Apr 2010 11:46:41 +0100
> From: Paul Taylor <paul_t100_at_fastmail.fm>
> Reply-To: users_at_jersey.dev.java.net
> To: users_at_jersey.dev.java.net
>
>
>
> Hi, I am having a problem displaying an int attribute in json for my
> tag element, without adding it the output looks okay
>
> if(tags.length>0)
> {
> TagList tagList = of.createTagList();
> for(int i = 0;i<tags.length;i++) {
> Tag tag = of.createTag();
> tag.setContent(tags[i]);
> *//tag.setCount(new BigInteger(tagCounts[i]));*
> tagList.getTag().add(tag);
> }
> recording.setTagList(tagList);
> }
>
> Xml is<?xml version="1.0" encoding="UTF-8" standalone="yes"?><metadata
> xmlns="http://musicbrainz.org/ns/mmd-2.0#"
> xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><recording-list
> offset="0" count="1"><recording ext:score="100"
> id="7ca7782b-a602-448b-b108-bb881a7be2d6"><title>Gravitational
> Lenz</title><length>234000</length><artist-credit><name-credit><artist
> id="4302e264-1cf0-4d1f-aca7-2a6f89e34b36"><name>Farming
> Incident</name><sort-name>Incident,
> Farming</sort-name></artist></name-credit></artist-credit><release-list><release
> id="1d9e8ed6-3893-4d3b-aa7d-6cd79609e386"><title>Our Glorious 5 Year
> Plan</title><status>official</status><release-group
> type="album"/><medium-list><track-count>10</track-count><medium><position>1</position><track-list
> offset="4" count="10"><track><title>Gravitational
> Lens</title></track></track-list></medium></medium-list></release></release-list><isrc-list><isrc
> id="123456789"/><isrc
> id="abcdefghi"/></isrc-list><*tag-list><tag>indie</tag></tag-list>*</recording></recording-list></metadata>
>
> Json
> is{"recording-list":{"offset":0,"count":1,"recording":[{"score":"100","id":"7ca7782b-a602-448b-b108-bb881a7be2d6","title":"Gravitational
> Lenz","length":234000,"artist-credit":{"name-credit":[{"artist":{"id":"4302e264-1cf0-4d1f-aca7-2a6f89e34b36","name":"Farming
> Incident","sort-name":"Incident,
> Farming"}}]},"release-list":{"release":[{"id":"1d9e8ed6-3893-4d3b-aa7d-6cd79609e386","title":"Our
> Glorious 5 Year
> Plan","status":"official","release-group":{"type":"album"},"medium-list":{"track-count":10,"medium":[{"position":1,"track-list":{"offset":4,"count":10,"track":[{"title":"Gravitational
> Lens"}]}}]}}]},"isrc-list":{"isrc":[{"id":"123456789"},{"id":"abcdefghi"}]},*"tag-list":{"tag":["indie"]}}]}}*
>
> I then uncomment the line
>
> if(tags.length>0)
> {
> TagList tagList = of.createTagList();
> for(int i = 0;i<tags.length;i++) {
> Tag tag = of.createTag();
> tag.setContent(tags[i]);
> *//tag.setCount(new BigInteger(tagCounts[i]));*
> tagList.getTag().add(tag);
> }
> recording.setTagList(tagList);
> }
>
> Xml is<?xml version="1.0" encoding="UTF-8" standalone="yes"?><metadata
> xmlns="http://musicbrainz.org/ns/mmd-2.0#"
> xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><recording-list
> offset="0" count="1"><recording ext:score="100"
> id="7ca7782b-a602-448b-b108-bb881a7be2d6"><title>Gravitational
> Lenz</title><length>234000</length><artist-credit><name-credit><artist
> id="4302e264-1cf0-4d1f-aca7-2a6f89e34b36"><name>Farming
> Incident</name><sort-name>Incident,
> Farming</sort-name></artist></name-credit></artist-credit><release-list><release
> id="1d9e8ed6-3893-4d3b-aa7d-6cd79609e386"><title>Our Glorious 5 Year
> Plan</title><status>official</status><release-group
> type="album"/><medium-list><track-count>10</track-count><medium><position>1</position><track-list
> offset="4" count="10"><track><title>Gravitational
> Lens</title></track></track-list></medium></medium-list></release></release-list><isrc-list><isrc
> id="123456789"/><isrc id="abcdefghi"/></isrc-list>*<tag-list><tag
> count="101">indie</tag></tag-list>*</recording></recording-list></metadata>
>
> Json
> is{"recording-list":{"offset":0,"count":1,"recording":[{"score":"100","id":"7ca7782b-a602-448b-b108-bb881a7be2d6","title":"Gravitational
> Lenz","length":234000,"artist-credit":{"name-credit":[{"artist":{"id":"4302e264-1cf0-4d1f-aca7-2a6f89e34b36","name":"Farming
> Incident","sort-name":"Incident,
> Farming"}}]},"release-list":{"release":[{"id":"1d9e8ed6-3893-4d3b-aa7d-6cd79609e386","title":"Our
> Glorious 5 Year
> Plan","status":"official","release-group":{"type":"album"},"medium-list":{"track-count":10,"medium":[{"position":1,"track-list":{"offset":4,"count":10,"track":[{"title":"Gravitational
> Lens"}]}}]}}]},"isrc-list":{"isrc":[{"id":"123456789"},{"id":"abcdefghi"}]},*"tag-list":{"tag":[{"count":101,"$":"indie"}]}}]}}*
>
> and now the json has a "$" field between 101 and indie, I dont know
> much about json but that isnt right is it ?
It is not a bug, as the "$" character marks the tag content, which
otherwise does not have any name.
This is how things are designed in this case.
Is the "$" name an issue for you? If so, do you have any suggestion
regarding how to compute more appropriate name?
~Jakub
>
> And this is the contents of the Tag class:
>
> //
> // This file was generated by the JavaTM Architecture for XML
> Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-792
> // See <a
> href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
> // Any modifications to this file will be lost upon recompilation of
> the source schema.
> // Generated on: 2010.03.25 at 10:49:46 PM GMT
> //
>
>
> package org.musicbrainz.mmd2;
>
> import java.math.BigInteger;
> import javax.xml.bind.annotation.XmlAccessType;
> import javax.xml.bind.annotation.XmlAccessorType;
> import javax.xml.bind.annotation.XmlAttribute;
> import javax.xml.bind.annotation.XmlRootElement;
> import javax.xml.bind.annotation.XmlSchemaType;
> import javax.xml.bind.annotation.XmlType;
> import javax.xml.bind.annotation.XmlValue;
>
>
> /**
> * <p>Java class for anonymous complex type.
> *
> * <p>The following schema fragment specifies the expected content
> contained within this class.
> *
> * <pre>
> * <complexType>
> * <complexContent>
> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
> * <attribute name="count"
> type="{http://www.w3.org/2001/XMLSchema}nonNegativeInteger" />
> * </restriction>
> * </complexContent>
> * </complexType>
> * </pre>
> *
> *
> */
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
> "content"
> })
> @XmlRootElement(name = "tag")
> public class Tag {
>
> @XmlValue
> protected String content;
> @XmlAttribute
> @XmlSchemaType(name = "nonNegativeInteger")
> protected BigInteger count;
>
> /**
> * Gets the value of the content property.
> *
> * @return
> * possible object is
> * {_at_link String }
> *
> */
> public String getContent() {
> return content;
> }
>
> /**
> * Sets the value of the content property.
> *
> * @param value
> * allowed object is
> * {_at_link String }
> *
> */
> public void setContent(String value) {
> this.content = value;
> }
>
> /**
> * Gets the value of the count property.
> *
> * @return
> * possible object is
> * {_at_link BigInteger }
> *
> */
> public BigInteger getCount() {
> return count;
> }
>
> /**
> * Sets the value of the count property.
> *
> * @param value
> * allowed object is
> * {_at_link BigInteger }
> *
> */
> public void setCount(BigInteger value) {
> this.count = value;
> }
>
> }
>
>
> thanks Paul
>