Simple (?) question concerning JSON root-Object

View: New views
6 Messages — Rating Filter:   Alert me  

Simple (?) question concerning JSON root-Object

by hairman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!
I didn't find an example and don't know how to search for the solution.

These annotations "generate" the following JSON:
@XmlRootElement
public class Object {
String key;
...
}

{ "object" :
       {
       "key" : "value"
       }
}


But how do I annotate the class to produce such a JSON:
{
  "key" : "value"
}



Re: Simple (?) question concerning JSON root-Object

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try this:

@XmlValue
  String key;

-W


On Thu, Sep 17, 2009 at 7:11 PM, hairman <sunti_online@...> wrote:

Hi!
I didn't find an example and don't know how to search for the solution.

These annotations "generate" the following JSON:
@XmlRootElement
public class Object {
String key;
...
}

{ "object" :
      {
      "key" : "value"
      }
}


But how do I annotate the class to produce such a JSON:
{
 "key" : "value"
}



--
View this message in context: http://www.nabble.com/Simple-%28-%29-question-concerning-JSON-root-Object-tp25492007p25492007.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...



Re: Simple (?) question concerning JSON root-Object

by hairman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!
Perhaps my problem doesn't directly refer to JAXB... I use JAXB annotations together with the RESTEasy Client framework.
With a bean like this:

@XmlRootElement(name = "simplebean")
public class SimpleBean {
    String key;
  ....
    @XmlValue
    public String getKey() {
        return key;
    }
I understandably get the following exception:
[javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"key"). Expected elements are <{}simplebean>]

Without @XmlRootElement(name = "simplebean") REStEasy won't find a MessageBodyReader to serialize/deserialize the bean.



Wolfgang Laun-2 wrote:
Try this:

@XmlValue
  String key;

-W


On Thu, Sep 17, 2009 at 7:11 PM, hairman <sunti_online@hotmail.com> wrote:

>
> Hi!
> I didn't find an example and don't know how to search for the solution.
>
> These annotations "generate" the following JSON:
> @XmlRootElement
> public class Object {
> String key;
> ...
> }
>
> { "object" :
>       {
>       "key" : "value"
>       }
> }
>
>
> But how do I annotate the class to produce such a JSON:
> {
>  "key" : "value"
> }
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Simple-%28-%29-question-concerning-JSON-root-Object-tp25492007p25492007.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@jaxb.dev.java.net
> For additional commands, e-mail: users-help@jaxb.dev.java.net
>
>

Re: Simple (?) question concerning JSON root-Object

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

To me,  the JSON { "key" : "value" } suggests that the object is called "key"; so probably this ought to be specified instead of simplebean as value of @XmlRootElement's name.
-W

On Fri, Sep 18, 2009 at 12:03 PM, hairman <sunti_online@...> wrote:

Hi!
Perhaps my problem doesn't directly refer to JAXB... I use JAXB annotations
together with the RESTEasy Client framework.
With a bean like this:

@XmlRootElement(name = "simplebean")
public class SimpleBean {
   String key;
 ....
   @XmlValue
   public String getKey() {
       return key;
   }
I understandably get the following exception:
[javax.xml.bind.UnmarshalException: unexpected element (uri:"",
local:"key"). Expected elements are <{}simplebean>]

Without @XmlRootElement(name = "simplebean") REStEasy won't find a
MessageBodyReader to serialize/deserialize the bean.




Wolfgang Laun-2 wrote:
>
> Try this:
>
> @XmlValue
>   String key;
>
> -W
>
>
> On Thu, Sep 17, 2009 at 7:11 PM, hairman <sunti_online@...> wrote:
>
>>
>> Hi!
>> I didn't find an example and don't know how to search for the solution.
>>
>> These annotations "generate" the following JSON:
>> @XmlRootElement
>> public class Object {
>> String key;
>> ...
>> }
>>
>> { "object" :
>>       {
>>       "key" : "value"
>>       }
>> }
>>
>>
>> But how do I annotate the class to produce such a JSON:
>> {
>>  "key" : "value"
>> }
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Simple-%28-%29-question-concerning-JSON-root-Object-tp25492007p25492007.html
>> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>
>

--
View this message in context: http://www.nabble.com/Simple-%28-%29-question-concerning-JSON-root-Object-tp25492007p25506173.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...



Re: Simple (?) question concerning JSON root-Object

by hairman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, you're right!
But for the following JSON there no longer is a "single" object name, to me:
 {
    "key" : "value",
    "key2" : "value2"
 }

I tried  "@XmlValue String[] values" but this produces {"key":"value value2"}




Wolfgang Laun-2 wrote:
To me,  the JSON { "key" : "value" } suggests that the object is called
"key"; so probably this ought to be specified instead of simplebean as value
of @XmlRootElement's name.
-W

On Fri, Sep 18, 2009 at 12:03 PM, hairman <sunti_online@hotmail.com> wrote:

>
> Hi!
> Perhaps my problem doesn't directly refer to JAXB... I use JAXB annotations
> together with the RESTEasy Client framework.
> With a bean like this:
>
> @XmlRootElement(name = "simplebean")
> public class SimpleBean {
>    String key;
>  ....
>    @XmlValue
>    public String getKey() {
>        return key;
>    }
> I understandably get the following exception:
> [javax.xml.bind.UnmarshalException: unexpected element (uri:"",
> local:"key"). Expected elements are <{}simplebean>]
>
> Without @XmlRootElement(name = "simplebean") REStEasy won't find a
> MessageBodyReader to serialize/deserialize the bean.
>
>
>
>
> Wolfgang Laun-2 wrote:
> >
> > Try this:
> >
> > @XmlValue
> >   String key;
> >
> > -W
> >
> >
> > On Thu, Sep 17, 2009 at 7:11 PM, hairman <sunti_online@hotmail.com>
> wrote:
> >
> >>
> >> Hi!
> >> I didn't find an example and don't know how to search for the solution.
> >>
> >> These annotations "generate" the following JSON:
> >> @XmlRootElement
> >> public class Object {
> >> String key;
> >> ...
> >> }
> >>
> >> { "object" :
> >>       {
> >>       "key" : "value"
> >>       }
> >> }
> >>
> >>
> >> But how do I annotate the class to produce such a JSON:
> >> {
> >>  "key" : "value"
> >> }
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Simple-%28-%29-question-concerning-JSON-root-Object-tp25492007p25492007.html
> >> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@jaxb.dev.java.net
> >> For additional commands, e-mail: users-help@jaxb.dev.java.net
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Simple-%28-%29-question-concerning-JSON-root-Object-tp25492007p25506173.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@jaxb.dev.java.net
> For additional commands, e-mail: users-help@jaxb.dev.java.net
>
>

Re: Simple (?) question concerning JSON root-Object

by Wolfgang Laun-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Please keep in mind that JAXB and it's cousins aren't capable of expressing all of Java in XML, and vice versa. JSON isn't a 100% equivalent for XML, so there may be incompatibilities which cannot be blamed on any of these systems.
-W

On Fri, Sep 18, 2009 at 2:29 PM, hairman <sunti_online@...> wrote:

Yes, you're right!
But for the following JSON there no longer is a "single" object name, to me:
 {
   "key" : "value",
   "key2" : "value2"
 }

I tried  "@XmlValue String[] values" but this produces {"key":"value
value2"}





Wolfgang Laun-2 wrote:
>
> To me,  the JSON { "key" : "value" } suggests that the object is called
> "key"; so probably this ought to be specified instead of simplebean as
> value
> of @XmlRootElement's name.
> -W
>
> On Fri, Sep 18, 2009 at 12:03 PM, hairman <sunti_online@...>
> wrote:
>
>>
>> Hi!
>> Perhaps my problem doesn't directly refer to JAXB... I use JAXB
>> annotations
>> together with the RESTEasy Client framework.
>> With a bean like this:
>>
>> @XmlRootElement(name = "simplebean")
>> public class SimpleBean {
>>    String key;
>>  ....
>>    @XmlValue
>>    public String getKey() {
>>        return key;
>>    }
>> I understandably get the following exception:
>> [javax.xml.bind.UnmarshalException: unexpected element (uri:"",
>> local:"key"). Expected elements are <{}simplebean>]
>>
>> Without @XmlRootElement(name = "simplebean") REStEasy won't find a
>> MessageBodyReader to serialize/deserialize the bean.
>>
>>
>>
>>
>> Wolfgang Laun-2 wrote:
>> >
>> > Try this:
>> >
>> > @XmlValue
>> >   String key;
>> >
>> > -W
>> >
>> >
>> > On Thu, Sep 17, 2009 at 7:11 PM, hairman <sunti_online@...>
>> wrote:
>> >
>> >>
>> >> Hi!
>> >> I didn't find an example and don't know how to search for the
>> solution.
>> >>
>> >> These annotations "generate" the following JSON:
>> >> @XmlRootElement
>> >> public class Object {
>> >> String key;
>> >> ...
>> >> }
>> >>
>> >> { "object" :
>> >>       {
>> >>       "key" : "value"
>> >>       }
>> >> }
>> >>
>> >>
>> >> But how do I annotate the class to produce such a JSON:
>> >> {
>> >>  "key" : "value"
>> >> }
>> >>
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Simple-%28-%29-question-concerning-JSON-root-Object-tp25492007p25492007.html
>> >> Sent from the java.net - jaxb users mailing list archive at
>> Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@...
>> >> For additional commands, e-mail: users-help@...
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Simple-%28-%29-question-concerning-JSON-root-Object-tp25492007p25506173.html
>> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>
>

--
View this message in context: http://www.nabble.com/Simple-%28-%29-question-concerning-JSON-root-Object-tp25492007p25507860.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...