Hi On 18/01/12 19:07, Chris Geer wrote:
I have a web service which supports both SOAP and RESTful calls which works great except for one small issue with JSON serialization on List results.I have two methods, one that returns a single entity and one that returns a List of entities. @GET @Path("/parcel/{id}") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Parcel getParcel(@PathParam("id") String id) {...} and @GET @Path("/parcels") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public List<Parcel> getParcels() {...} When these methods are called via SOAP or Rest with XML return it all works perfectly. When I call with JSON return it all looks decent but breaks down. With no JSONProvider configuration the results look like this: getParcel {"ns1.Parcel": { "ns1.ParcelID": 26, "ns1.Fragile": false, "ns1.Weight": 34 }} getParcels {"ns1.Parcel": [ { "ns1.ParcelID": 1, "ns1.Fragile": true, "ns1.Weight": 100}, { "ns1.ParcelID": 2, "ns1.Fragile": false, "ns1.Weight": 1000} ]} Since the ns1 prefix is "random" (it's changed on me several times) I wanted to define my own static prefix so I added a namespace map to the JSONProvider and get these results getParcel {"p.Parcel": { "p.ParcelID": 26, "p.Fragile": false, "p.Weight": 34 }} getParcels {"ns1.Parcel": [ { "p.ParcelID": 1, "p.Fragile": true, "p.Weight": 100}, { "p.ParcelID": 2, "p.Fragile": false, "p.Weight": 1000} ]} The return of the single item came across as I expected (everything with a single prefix p) but the List return still had the collection node with the random ns1 prefix. Since that didn't work the way I wanted, I removed the namespace map and added<property name="ignoreNamespaces" value="true"/> and got these results getParcel {"Parcel": { "ParcelID": 26, "Fragile": false, "Weight": 34 }} getParcels {"ns1.Parcel": [ {"Parcel": { "ParcelID": 1, "Fragile": true, "Weight": 100}}, {"Parcel": { "ParcelID": 2, "Fragile": false, "Weight": 1000}} ]} Again, the single item came across fine but the List return wasn't what I expected at all. I also tried to fool with some of the other options but nothing I could try seemed to work. I want to get rid of the ns1 prefix on the List wrapper element but can't figure it out.
I've got it fixed, please consider introducing a Parcels wrapper bean is a workaround, but either ignoreNamespaces or setting a prefix in the namespaceMap will do it for the wrapper element in the next versions
Cheers, Sergey
Thanks, Chris
-- Sergey Beryozkin Talend Community Coders http://coders.talend.com/ Blog: http://sberyozkin.blogspot.com
