stratos-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Imesh Gunaratne <>
Subject [Discuss] [REST API] Removing The Wrapping Object in the Collection Responses
Date Sun, 14 Dec 2014 06:02:26 GMT
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:


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

<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider">

    <property name="dropCollectionWrapperElement" value="true"/>


*New sample response:*


*Sample code to de-serialize the object:*

Type listType = new TypeToken<ArrayList<CartridgeDefinitionBean>>()
List<CartridgeDefinitionBean> cartridgeList =
        listType, "cartridges");

Dakshika: We might need to update the UI with this modification. Really
sorry for the inconvenience that may cause.


Imesh Gunaratne

Technical Lead, WSO2
Committer & PMC Member, Apache Stratos

View raw message