Gautam Arora wrote:
> Problem solved.
>
Great.
> Hi Naresh,
> I added the JAXBContentResolver.java to the pet catalog app and made it
> refer to the appropriate JAXB classes. Now the provider class gets detected
> and the root element is displayed :)
>
> Now when I go back and read Japod's blog I understood what he was referring
> to.
>
May be you should try going through the [samples] too, that might give
you a good start with Building RESTful Web Services using Jersey.
[samples]
http://download.java.net/maven/2/com/sun/jersey/samples/jersey-samples/1.0.2/jersey-samples-1.0.2-project.zip
-Naresh
> Thanks a lot for your help in getting me around this.
>
> Thanks,
> Gautam Arora
>
>
> Gautam Arora wrote:
>
>> Hi Naresh,
>>
>> I got the json-from-jaxb project and edited the JAXBContentResolver as:
>> this.context = new
>> JSONJAXBContext(JSONConfiguration.mapped().rootUnwrapping(false).build(),
>> cTypes);
>>
>> This worked and I now get the root element in the json :) Awesome!
>>
>> The code in this project also looks much simpler to understand than the
>> code generated using the "RESTful Web Services using Entity classes" in
>> Netbeans. Unless there was a way to understand what the whole automagic
>> was and how a Provider class could be provided.
>>
>> Thanks, I'll look at more samples and learn from them.
>>
>> Gautam
>>
>>
>> Naresh-2 wrote:
>>
>>> Gautam Arora wrote:
>>>
>>>> Well, thats true but in the link:
>>>> http://weblogs.java.net/blog/caroljmcdonald/archive/2008/08/a_restful_pet_c_1.html
>>>> on the table "Example json data"
>>>> It shows the generation of the root element.
>>>>
>>>> You could be correct that as such, the author expected this to be the
>>>> behavior and had no issues with parsing it in a dojo grid but I ran into
>>>> issues with YUI :)
>>>> I'll look into how to define and ContextProvider class and set the
>>>> rootUnwrapping=false.
>>>>
>>>> Early days for me using Jersey. Thanks for your help.
>>>> Incase you have some links/pointers to tutorials/samples that address
>>>> this
>>>> generation of root element, do let me know. I could look and learn.
>>>>
>>>>
>>> Please have a look at the Jersey samples [jsonp] and [json-from-jaxb].
>>>
>>> [jsonp]
>>> http://download.java.net/maven/2/com/sun/jersey/samples/jsonp/1.0.2/jsonp-1.0.2-project.zip
>>> [json-from-jaxb]
>>> http://download.java.net/maven/2/com/sun/jersey/samples/json-from-jaxb/1.0.2/json-from-jaxb-1.0.2-project.zip
>>>
>>> -Naresh
>>>
>>>
>>>> Thanks,
>>>> Gautam
>>>>
>>>>
>>>> Srinivas Naresh Bhimisetty wrote:
>>>>
>>>>
>>>>> May be the sample is not using any @Provider annotated class, because
>>>>> its showing the data in default JSON format. But as you said, your
>>>>> requirement is to get the root element (i.e., items) too. For this you
>>>>> will have to define a ContextProvider class, and set the
>>>>> "rootUnwrapping" to "false" (the default is "true").
>>>>>
>>>>> Hope this helps,
>>>>> Naresh
>>>>>
>>>>> Gautam Arora wrote:
>>>>>
>>>>>
>>>>>> Naresh,
>>>>>> Yes you seem to be pointing in the right direction.
>>>>>> To start with, the pet catalog app does not have any class with a
>>>>>> @Provider
>>>>>> annotation
>>>>>> also, my logs are:
>>>>>> ---------------------------------------------------------------------------------
>>>>>> etc etc
>>>>>> Scanning for root resource and provider classes in the paths:
>>>>>> /Users/gautam/NetBeansProjects/catalogitem/build/web/WEB-INF/lib
>>>>>> /Users/gautam/NetBeansProjects/catalogitem/build/web/WEB-INF/classes
>>>>>> Root resource classes found:
>>>>>> class service.ItemsResource
>>>>>> Provider classes found:
>>>>>> ---------------------------------------------------------------------------------
>>>>>>
>>>>>> There is no Provider class listed after the statement "Provider
>>>>>> classes
>>>>>> found" and I was finding this weird as to why nothing is displayed
>>>>>> after
>>>>>> that line.
>>>>>>
>>>>>> This is as per the code available at:
>>>>>> https://techdayscode.dev.java.net/files/documents/7105/106278/catalog.zip
>>>>>>
>>>>>> for the RESTful Pet Catalog app:
>>>>>> http://weblogs.java.net/blog/caroljmcdonald/archive/2008/08/a_restful_pet_c_1.html
>>>>>>
>>>>>> To get the project to this state, all one has to do is:
>>>>>> 1. Generate Entity classes from database (Table Item or anything else)
>>>>>> 2. Generate Restful Web Services from Entity classes
>>>>>>
>>>>>> The "Example JSON Data" section of this tutorial does seem to show
>>>>>> that
>>>>>> the
>>>>>> "items" element should be generated and mentions nothing about a
>>>>>> @Provider
>>>>>> annotation.
>>>>>>
>>>>>> Could you suggest any more investigative steps or have a look at the
>>>>>> code
>>>>>> in
>>>>>> the above link.
>>>>>>
>>>>>> Thanks,
>>>>>> Gautam
>>>>>>
>>>>>>
>>>>>>
>>>>>> Srinivas Naresh Bhimisetty wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>> Hi Gautam,
>>>>>>>
>>>>>>> I doubt if your Provider class is being detected or not, are you
>>>>>>> able
>>>>>>> to see some message like:
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>>> INFO: Provider classes found:
>>>>>>> class /yourContextResolver
>>>>>>> -------------------------------------------------------------
>>>>>>>
>>>>>>> /in the logs.
>>>>>>>
>>>>>>> -Naresh
>>>>>>>
>>>>>>>
>>>>>>> Gautam Arora wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> Hi Naresh,
>>>>>>>>
>>>>>>>> I set rootUnwrapping to false, but still same output as before i.e.
>>>>>>>> root
>>>>>>>> element is dropped
>>>>>>>>
>>>>>>>> Let me know if you have any more ideas on what I could try, I'll try
>>>>>>>> them
>>>>>>>> in
>>>>>>>> realtime (well, almost!) :)
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Gautam
>>>>>>>>
>>>>>>>>
>>>>>>>> Srinivas Naresh Bhimisetty wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>> Hi Gautam,
>>>>>>>>>
>>>>>>>>> could you try setting rootUnwrapping to 'false' instead, i.e.,
>>>>>>>>>
>>>>>>>>> JAXBContext context = new
>>>>>>>>> JSONJAXBContext(JSONConfiguration.mapped().rootUnwrapping(false).arrays("items").build(),type);
>>>>>>>>>
>>>>>>>>> Hope this helps,
>>>>>>>>> Naresh
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Gautam Arora wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> update:
>>>>>>>>>>
>>>>>>>>>> 1. I moved to Jersey 1.0.2 (downloaded it and added to netbeans)
>>>>>>>>>> 2. Edited the UriResolver.resolve() method
>>>>>>>>>> original: JAXBContext context = JAXBContext.newInstance(type);
>>>>>>>>>> modified: JAXBContext context = new
>>>>>>>>>> JSONJAXBContext(JSONConfiguration.mapped().rootUnwrapping(true).arrays("items").build(),type);
>>>>>>>>>>
>>>>>>>>>> This was as per the steps given at
>>>>>>>>>> http://blogs.sun.com/japod/entry/configuring_json_for_restful_web
>>>>>>>>>>
>>>>>>>>>> But the root element is still getting dropped. Any tips on how to
>>>>>>>>>> make
>>>>>>>>>> this
>>>>>>>>>> work with this app?
>>>>>>>>>>
>>>>>>>>>> Gautam
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Gautam Arora wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>> I'm following the RESTful Pet Catalog tutorial from
>>>>>>>>>>> http://weblogs.java.net/blog/caroljmcdonald/archive/2008/08/a_restful_pet_c_1.html
>>>>>>>>>>>
>>>>>>>>>>> The expected JSON response (as per the tutorial is)
>>>>>>>>>>> http://localhost:8080/catalog/resources/items/
>>>>>>>>>>>
>>>>>>>>>>> {"items":{"@uri":"http://localhost:8080/catalog/resources/items","item":[{
>>>>>>>>>>> etc etc
>>>>>>>>>>>
>>>>>>>>>>> but I get the response as:
>>>>>>>>>>> {"@uri":"http://localhost:8080/catalog/resources/items","item":[{
>>>>>>>>>>> etc
>>>>>>>>>>> etc
>>>>>>>>>>>
>>>>>>>>>>> The "items" label is dropped.
>>>>>>>>>>> I've read here on forum posts that say that dropping off the root
>>>>>>>>>>> element
>>>>>>>>>>> is a desired feature and with newer releases of jersey it should
>>>>>>>>>>> be
>>>>>>>>>>> fixed(/configurable?)
>>>>>>>>>>>
>>>>>>>>>>> I've developed the app myself and also tested the same app by
>>>>>>>>>>> downloading
>>>>>>>>>>> it and running it and and running into the same issue.
>>>>>>>>>>>
>>>>>>>>>>> I'm using Jersey 1.0. Is this issue fixed in 1.0.2?
>>>>>>>>>>>
>>>>>>>>>>> Whats the best way to make jersey1.0 generate the "items" label
>>>>>>>>>>> for
>>>>>>>>>>> this
>>>>>>>>>>> app? I've read on posts that we need to add a property for the
>>>>>>>>>>> json
>>>>>>>>>>> unwrapping but cant figure out where/how to put it in the pet
>>>>>>>>>>> catalog
>>>>>>>>>>> sample app.
>>>>>>>>>>>
>>>>>>>>>>> I need this as I'm using YUI which expects this and throws an
>>>>>>>>>>> invalid
>>>>>>>>>>> label error otherwise
>>>>>>>>>>> As per the tutorial, having the label is the expected behavior,
>>>>>>>>>>> so
>>>>>>>>>>> any
>>>>>>>>>>> reasons why I could be missing it?
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Gautam
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>>
>>>
>>>
>>
>
>