Thanks Udara! We have now resolved this with CXF JSON provider
configuration.
Thanks Dakshika, please let us know if you find any problems.

On Sun, Dec 14, 2014 at 11:43 AM, Dakshika Jayathilaka <daksh...@wso2.com>
wrote:
>
> Hi Imesh,
>
> I'll check and update.
>
> Thank you,
>
> *Dakshika Jayathilaka*
> Software Engineer
> WSO2, Inc.
> lean.enterprise.middleware
> 0771100911
>
> On Sun, Dec 14, 2014 at 11:42 AM, Udara Liyanage <ud...@wso2.com> wrote:
>>
>> Hi Imesh,
>>
>> If we are switching to Jackson json provider(there is a discussion
>> previously)  this may be already resolved. It supports java collections.
>>
>>
>> Touched, not typed. Erroneous words are a feature, not a typo.
>> On Dec 14, 2014 11:32 AM, "Imesh Gunaratne" <im...@apache.org> wrote:
>>
>>> Hi Devs,
>>>
>>> All the REST API methods which return collection types have included a
>>> wrapper object in their response messages. This is according to the CXF
>>> JSON provider configuration.
>>>
>>> Example: GET Cartridges:
>>>
>>> {"*cartridges*":[{"category":"framework","description":"Apache
>>> Tomcat","displayName":"tomcat","host":"tomcat.apache.org
>>> ","multiTenant":false,"provider":"apache","public":false,"type":"tomcat","version":7}]}
>>>
>>> This becomes a problem for the CLI or for any other client that try to
>>> deserialize the JSON string to its corresponding Java object. The
>>> convention we had used to resolve this issue was to define wrapper classes
>>> for collection type responses:
>>>
>>>     private class CartridgeList {
>>>         private ArrayList<Cartridge> cartridges;
>>>
>>>         public ArrayList<Cartridge> getCartridges() {
>>>             return cartridges;
>>>         }
>>>
>>>         public void setCartridge(ArrayList<Cartridge> cartridges) {
>>>             this.cartridges = cartridges;
>>>         }
>>>
>>>         CartridgeList() {
>>>             cartridges = new ArrayList<Cartridge>();
>>>         }
>>>     }
>>>
>>> IMO this is an overhead when considering the amount of classes we have
>>> in the REST API domain model.
>>>
>>> As a solution to this problem I have now configured REST API to remove
>>> this element:
>>>
>>> <bean id="jsonProvider" 
>>> class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>>>
>>>     ...
>>>     <property name="dropCollectionWrapperElement" value="true"/>
>>>
>>>     ...
>>> </bean>
>>>
>>>
>>> *New sample response:*
>>>
>>> [{"category":"framework","description":"Apache 
>>> Tomcat","displayName":"tomcat","host":"tomcat.apache.org","multiTenant":false,"provider":"apache","public":false,"type":"tomcat","version":7}]
>>>
>>> *Sample code to de-serialize the object:*
>>>
>>> Type listType = new TypeToken<ArrayList<CartridgeDefinitionBean>>() 
>>> {}.getType();
>>> List<CartridgeDefinitionBean> cartridgeList = 
>>> (List<CartridgeDefinitionBean>) 
>>> restClient.listEntity(ENDPOINT_LIST_CARTRIDGES,
>>>         listType, "cartridges");
>>>
>>>
>>> Dakshika: We might need to update the UI with this modification. Really
>>> sorry for the inconvenience that may cause.
>>>
>>> Thanks
>>>
>>>
>>>
>>> --
>>> Imesh Gunaratne
>>>
>>> Technical Lead, WSO2
>>> Committer & PMC Member, Apache Stratos
>>>
>>

-- 
Imesh Gunaratne

Technical Lead, WSO2
Committer & PMC Member, Apache Stratos

Reply via email to