You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stratos.apache.org by Udara Liyanage <ud...@wso2.com> on 2014/11/05 14:05:20 UTC

Json response shows arrays as string when there are single value

Hi,

When I execute the GET serviceGroup Stratos endpoint I get the folowing
output in two different groups. Please note cartridges text  in bold. When
there are only one cartridge, it shows as a String (output1), when there
are multiple cartridges it is shown as an array (output2).

But when I convert the object to a json text, it shows as arrays even when
there are single cartridge.

The issue happens when the object is sent in response as below

return Response.ok().entity(serviceGroupDefinition).build();


In the code carridges is set as a list.


   1. List<String> cartridgesDef = new ArrayList<String>(Arrays.asList(
   cartridges));
   2. servicegroupDef.setCartridges(cartridgesDef);


[1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml, I
tried doing it too. But same result.

What is the reason for this?


output [1]

{
    "serviceGroup": [
        {
           * "cartridges": "tomcat",*
            "dependencies": {
                "startupOrders": "group.group1,cartridge.tomcat",
                "terminationBehaviour": "terminate-dependents"
            },
            "name": "group5",
            "subGroups": "group1"
        }
    ]
}

output [2]

{
    "serviceGroup": {
        "cartridges": *[*
*            "tomcat",*
*            "php"*
*        ],*
        "dependencies": {
            "startupOrders": "group.group1,cartridge.tomcat",
            "terminationBehaviour": "terminate-dependents"
        },
        "name": "group6",
        "subGroups": "group2"
    }
}

[1]
http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
-- 

Udara Liyanage
Software Engineer
WSO2, Inc.: http://wso2.com
lean. enterprise. middleware

web: http://udaraliyanage.wordpress.com
phone: +94 71 443 6897

Re: Json response shows arrays as string when there are single value

Posted by Nirmal Fernando <ni...@gmail.com>.
I think this is a limitation of the JSON library.

On Wed, Nov 5, 2014 at 2:05 PM, Udara Liyanage <ud...@wso2.com> wrote:

> Hi,
>
> When I execute the GET serviceGroup Stratos endpoint I get the folowing
> output in two different groups. Please note cartridges text  in bold. When
> there are only one cartridge, it shows as a String (output1), when there
> are multiple cartridges it is shown as an array (output2).
>
> But when I convert the object to a json text, it shows as arrays even when
> there are single cartridge.
>
> The issue happens when the object is sent in response as below
>
> return Response.ok().entity(serviceGroupDefinition).build();
>
>
> In the code carridges is set as a list.
>
>
>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.asList(
>    cartridges));
>    2. servicegroupDef.setCartridges(cartridgesDef);
>
>
> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml, I
> tried doing it too. But same result.
>
> What is the reason for this?
>
>
> output [1]
>
> {
>     "serviceGroup": [
>         {
>            * "cartridges": "tomcat",*
>             "dependencies": {
>                 "startupOrders": "group.group1,cartridge.tomcat",
>                 "terminationBehaviour": "terminate-dependents"
>             },
>             "name": "group5",
>             "subGroups": "group1"
>         }
>     ]
> }
>
> output [2]
>
> {
>     "serviceGroup": {
>         "cartridges": *[*
> *            "tomcat",*
> *            "php"*
> *        ],*
>         "dependencies": {
>             "startupOrders": "group.group1,cartridge.tomcat",
>             "terminationBehaviour": "terminate-dependents"
>         },
>         "name": "group6",
>         "subGroups": "group2"
>     }
> }
>
> [1]
> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
> --
>
> Udara Liyanage
> Software Engineer
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
>
> web: http://udaraliyanage.wordpress.com
> phone: +94 71 443 6897
>



-- 
Best Regards,
Nirmal

Nirmal Fernando.
PPMC Member & Committer of Apache Stratos,
Senior Software Engineer, WSO2 Inc.

Blog: http://nirmalfdo.blogspot.com/

Re: Json response shows arrays as string when there are single value

Posted by Manula Chathurika Thantriwatte <ma...@wso2.com>.
Hi Udara,

I think we can go to the option 1 you mentioned rather than moving to
JacksonJaxbJsonProvide.
IMO is better to move JacksonJaxbJsonProvide after M4.

Thanks !

On Thu, Nov 6, 2014 at 11:25 PM, Udara Liyanage <ud...@wso2.com> wrote:

> Hi Manula,
>
> Not yet committed. I have tool two paths to resolve this which I succeeded
> in both paths.
>
> 1) I added below variables to the cxf-servelet.xml as below
>                 <value>cartridges</value>
>                 <value>startupOrders</value>
>                 <value>dependencies</value>
>
> There I was able to get the expected outcome. However this is kind of
> cumbersome since we have to add variable names of all lists to the
> servlet.xml. This is not maintainable friendly way.
>
> 2) changing json provider
> Please refer to the thread "Moving to JacksonJaxbJsonProvide json provider
> in Stratos REST API".  This may have impact on the CLI funtions since root
> element is not available when using this provider. Since the M4 is just
> around the corner, it may be wiser to hold this method since release.
>
> @Lakmal @Imesh what do you think?
>
> On Thu, Nov 6, 2014 at 4:29 PM, Manula Chathurika Thantriwatte <
> manulac@wso2.com> wrote:
>
>> Hi Udara,
>>
>> Have you commit the changes.
>>
>> On Wed, Nov 5, 2014 at 8:16 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>
>>> Hi Nirmal,
>>>
>>> Yes I already changed some endpoints which seems to work fine. I will
>>> test others and will update the thread.
>>>
>>> On Wed, Nov 5, 2014 at 8:08 PM, Nirmal Fernando <ni...@gmail.com>
>>> wrote:
>>>
>>>>
>>>>
>>>> On Wed, Nov 5, 2014 at 3:31 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> It works when I changed the Json provider to
>>>>> org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
>>>>>
>>>>>
>>>>> <bean id="jsonProvider"
>>>>> class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider">
>>>>>
>>>>
>>>> Yes, this is what I meant. It's a limitation of the earlier library we
>>>> used. +1 from me for this change, but please test all operations.
>>>>
>>>>     </bean>
>>>>>
>>>>> If we are using the above provider we do not need to specify
>>>>> serializeAsArray for any property as we have now.  In addition it
>>>>> automatically remove the root element. I pasted the existing JsonProvider
>>>>> configurations below.
>>>>>
>>>>>     <bean id="jsonProvider"
>>>>> class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>>>>>         <property name="supportUnwrapped" value="true"/>
>>>>>         <property name="serializeAsArray" value="true"/>
>>>>>         <property name="arrayKeys">
>>>>>             <list>
>>>>>                 <value>partitions</value>
>>>>>                 <value>property</value>
>>>>>                 <value>hostNames</value>
>>>>>                 <value>memberMap</value>
>>>>>                 <value>portMap</value>
>>>>>                 <value>partitionGroup</value>
>>>>>                 <value>member</value>
>>>>>                 <value>hostNames</value>
>>>>>                 <value>portMappings</value>
>>>>>                 <value>volumes</value>
>>>>>                 <value>domains</value>
>>>>>                 <value>kubernetesHost</value>
>>>>>                 <value>cartridges</value>
>>>>>             </list>
>>>>>         </property>
>>>>>     </bean>
>>>>> -->
>>>>>
>>>>>
>>>>> On Wed, Nov 5, 2014 at 7:53 PM, Nirmal Fernando <
>>>>> nirmal070125@gmail.com> wrote:
>>>>>
>>>>>> May be we have to use element wrapper; @XmlElementWrapper(name=
>>>>>> "cartridges")
>>>>>>
>>>>>> http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html
>>>>>>
>>>>>> On Wed, Nov 5, 2014 at 3:11 PM, Udara Liyanage <ud...@wso2.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> You can find it [1]. Please note that other bean classes have public
>>>>>>> variables which are set when converting to a pojo. This bean as private
>>>>>>> variables and public getters and setters.
>>>>>>>
>>>>>>> [1]
>>>>>>> https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java
>>>>>>>
>>>>>>> On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <
>>>>>>> nirmal070125@gmail.com> wrote:
>>>>>>>
>>>>>>>> Can you point to the relevant rest endpoint bean ?
>>>>>>>>
>>>>>>>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Hi Nirmal,
>>>>>>>>>
>>>>>>>>> But it works in get deployment policy endpoint, so it can not be a
>>>>>>>>> limitation ?
>>>>>>>>>
>>>>>>>>> curl -X GET -H "Content-Type: application/json" -d
>>>>>>>>> @'app-php-only.json' -k   -u admin:admin
>>>>>>>>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>>>>>>>>> | python -m json.tool
>>>>>>>>>   % Total    % Received % Xferd  Average Speed   Time    Time
>>>>>>>>> Time  Current
>>>>>>>>>                                  Dload  Upload   Total   Spent
>>>>>>>>>  Left  Speed
>>>>>>>>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:--
>>>>>>>>> --:--:--  8538
>>>>>>>>> {
>>>>>>>>>     "deploymentPolicy": {
>>>>>>>>>         "id": "economyDeploymentPolicy",
>>>>>>>>>         "partitionGroup": [
>>>>>>>>>             {
>>>>>>>>>                 "id": "ec2",
>>>>>>>>>                 *"partition": [*
>>>>>>>>> *                    {*
>>>>>>>>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>>>>>>>>> *                        "isPublic": false,*
>>>>>>>>> *                        "partitionMax": 3,*
>>>>>>>>> *                        "partitionMin": 1,*
>>>>>>>>> *                        "property": [*
>>>>>>>>> *                            {*
>>>>>>>>> *                                "name": "region",*
>>>>>>>>> *                                "value": "ap-southeast-1"*
>>>>>>>>> *                            },*
>>>>>>>>> *                            {*
>>>>>>>>> *                                "name": "zone",*
>>>>>>>>> *                                "value": "ap-southeast-1a"*
>>>>>>>>> *                            }*
>>>>>>>>> *                        ],*
>>>>>>>>> *                        "provider": "ec2"*
>>>>>>>>> *                    }*
>>>>>>>>> *                ],*
>>>>>>>>>                 "partitionAlgo": "one-after-another"
>>>>>>>>>             }
>>>>>>>>>         ],
>>>>>>>>>         "public": false
>>>>>>>>>     }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>>>>>>>>> now cartridges are shown as arrays.
>>>>>>>>>> <value>cartridges</value>
>>>>>>>>>>
>>>>>>>>>> But we can't specify it for each variable.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> When I execute the GET serviceGroup Stratos endpoint I get the
>>>>>>>>>>> folowing output in two different groups. Please note cartridges text  in
>>>>>>>>>>> bold. When there are only one cartridge, it shows as a String (output1),
>>>>>>>>>>> when there are multiple cartridges it is shown as an array (output2).
>>>>>>>>>>>
>>>>>>>>>>> But when I convert the object to a json text, it shows as arrays
>>>>>>>>>>> even when there are single cartridge.
>>>>>>>>>>>
>>>>>>>>>>> The issue happens when the object is sent in response as below
>>>>>>>>>>>
>>>>>>>>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> In the code carridges is set as a list.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.
>>>>>>>>>>>    asList(cartridges));
>>>>>>>>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>>>>>>>>> I tried doing it too. But same result.
>>>>>>>>>>>
>>>>>>>>>>> What is the reason for this?
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> output [1]
>>>>>>>>>>>
>>>>>>>>>>> {
>>>>>>>>>>>     "serviceGroup": [
>>>>>>>>>>>         {
>>>>>>>>>>>            * "cartridges": "tomcat",*
>>>>>>>>>>>             "dependencies": {
>>>>>>>>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>>>>>>>>             },
>>>>>>>>>>>             "name": "group5",
>>>>>>>>>>>             "subGroups": "group1"
>>>>>>>>>>>         }
>>>>>>>>>>>     ]
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> output [2]
>>>>>>>>>>>
>>>>>>>>>>> {
>>>>>>>>>>>     "serviceGroup": {
>>>>>>>>>>>         "cartridges": *[*
>>>>>>>>>>> *            "tomcat",*
>>>>>>>>>>> *            "php"*
>>>>>>>>>>> *        ],*
>>>>>>>>>>>         "dependencies": {
>>>>>>>>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>>>>>             "terminationBehaviour": "terminate-dependents"
>>>>>>>>>>>         },
>>>>>>>>>>>         "name": "group6",
>>>>>>>>>>>         "subGroups": "group2"
>>>>>>>>>>>     }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> [1]
>>>>>>>>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>>>>>>>>> --
>>>>>>>>>>>
>>>>>>>>>>> Udara Liyanage
>>>>>>>>>>> Software Engineer
>>>>>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>>>>>> lean. enterprise. middleware
>>>>>>>>>>>
>>>>>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>>>>>> phone: +94 71 443 6897
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>>
>>>>>>>>>> Udara Liyanage
>>>>>>>>>> Software Engineer
>>>>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>>>>> lean. enterprise. middleware
>>>>>>>>>>
>>>>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>>>>> phone: +94 71 443 6897
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> Udara Liyanage
>>>>>>>>> Software Engineer
>>>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>>>> lean. enterprise. middleware
>>>>>>>>>
>>>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>>>> phone: +94 71 443 6897
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Best Regards,
>>>>>>>> Nirmal
>>>>>>>>
>>>>>>>> Nirmal Fernando.
>>>>>>>> PPMC Member & Committer of Apache Stratos,
>>>>>>>> Senior Software Engineer, WSO2 Inc.
>>>>>>>>
>>>>>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>> Udara Liyanage
>>>>>>> Software Engineer
>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>> lean. enterprise. middleware
>>>>>>>
>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>> phone: +94 71 443 6897
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Best Regards,
>>>>>> Nirmal
>>>>>>
>>>>>> Nirmal Fernando.
>>>>>> PPMC Member & Committer of Apache Stratos,
>>>>>> Senior Software Engineer, WSO2 Inc.
>>>>>>
>>>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Udara Liyanage
>>>>> Software Engineer
>>>>> WSO2, Inc.: http://wso2.com
>>>>> lean. enterprise. middleware
>>>>>
>>>>> web: http://udaraliyanage.wordpress.com
>>>>> phone: +94 71 443 6897
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Best Regards,
>>>> Nirmal
>>>>
>>>> Nirmal Fernando.
>>>> PPMC Member & Committer of Apache Stratos,
>>>> Senior Software Engineer, WSO2 Inc.
>>>>
>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Udara Liyanage
>>> Software Engineer
>>> WSO2, Inc.: http://wso2.com
>>> lean. enterprise. middleware
>>>
>>> web: http://udaraliyanage.wordpress.com
>>> phone: +94 71 443 6897
>>>
>>
>>
>>
>> --
>> Regards,
>> Manula Chathurika Thantriwatte
>> Software Engineer
>> WSO2 Inc. : http://wso2.com
>> lean . enterprise . middleware
>>
>> email : manulac@wso2.com / manula@apache.org
>> phone : +94 772492511
>> blog : http://manulachathurika.blogspot.com/
>>
>>
>>
>>
>
>
> --
>
> Udara Liyanage
> Software Engineer
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
>
> web: http://udaraliyanage.wordpress.com
> phone: +94 71 443 6897
>



-- 
Regards,
Manula Chathurika Thantriwatte
Software Engineer
WSO2 Inc. : http://wso2.com
lean . enterprise . middleware

email : manulac@wso2.com / manula@apache.org
phone : +94 772492511
blog : http://manulachathurika.blogspot.com/

Re: Json response shows arrays as string when there are single value

Posted by Udara Liyanage <ud...@wso2.com>.
Hi Manula,

Not yet committed. I have tool two paths to resolve this which I succeeded
in both paths.

1) I added below variables to the cxf-servelet.xml as below
                <value>cartridges</value>
                <value>startupOrders</value>
                <value>dependencies</value>

There I was able to get the expected outcome. However this is kind of
cumbersome since we have to add variable names of all lists to the
servlet.xml. This is not maintainable friendly way.

2) changing json provider
Please refer to the thread "Moving to JacksonJaxbJsonProvide json provider
in Stratos REST API".  This may have impact on the CLI funtions since root
element is not available when using this provider. Since the M4 is just
around the corner, it may be wiser to hold this method since release.

@Lakmal @Imesh what do you think?

On Thu, Nov 6, 2014 at 4:29 PM, Manula Chathurika Thantriwatte <
manulac@wso2.com> wrote:

> Hi Udara,
>
> Have you commit the changes.
>
> On Wed, Nov 5, 2014 at 8:16 PM, Udara Liyanage <ud...@wso2.com> wrote:
>
>> Hi Nirmal,
>>
>> Yes I already changed some endpoints which seems to work fine. I will
>> test others and will update the thread.
>>
>> On Wed, Nov 5, 2014 at 8:08 PM, Nirmal Fernando <ni...@gmail.com>
>> wrote:
>>
>>>
>>>
>>> On Wed, Nov 5, 2014 at 3:31 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> It works when I changed the Json provider to
>>>> org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
>>>>
>>>>
>>>> <bean id="jsonProvider"
>>>> class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider">
>>>>
>>>
>>> Yes, this is what I meant. It's a limitation of the earlier library we
>>> used. +1 from me for this change, but please test all operations.
>>>
>>>     </bean>
>>>>
>>>> If we are using the above provider we do not need to specify
>>>> serializeAsArray for any property as we have now.  In addition it
>>>> automatically remove the root element. I pasted the existing JsonProvider
>>>> configurations below.
>>>>
>>>>     <bean id="jsonProvider"
>>>> class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>>>>         <property name="supportUnwrapped" value="true"/>
>>>>         <property name="serializeAsArray" value="true"/>
>>>>         <property name="arrayKeys">
>>>>             <list>
>>>>                 <value>partitions</value>
>>>>                 <value>property</value>
>>>>                 <value>hostNames</value>
>>>>                 <value>memberMap</value>
>>>>                 <value>portMap</value>
>>>>                 <value>partitionGroup</value>
>>>>                 <value>member</value>
>>>>                 <value>hostNames</value>
>>>>                 <value>portMappings</value>
>>>>                 <value>volumes</value>
>>>>                 <value>domains</value>
>>>>                 <value>kubernetesHost</value>
>>>>                 <value>cartridges</value>
>>>>             </list>
>>>>         </property>
>>>>     </bean>
>>>> -->
>>>>
>>>>
>>>> On Wed, Nov 5, 2014 at 7:53 PM, Nirmal Fernando <nirmal070125@gmail.com
>>>> > wrote:
>>>>
>>>>> May be we have to use element wrapper; @XmlElementWrapper(name=
>>>>> "cartridges")
>>>>>
>>>>> http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html
>>>>>
>>>>> On Wed, Nov 5, 2014 at 3:11 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> You can find it [1]. Please note that other bean classes have public
>>>>>> variables which are set when converting to a pojo. This bean as private
>>>>>> variables and public getters and setters.
>>>>>>
>>>>>> [1]
>>>>>> https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java
>>>>>>
>>>>>> On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <
>>>>>> nirmal070125@gmail.com> wrote:
>>>>>>
>>>>>>> Can you point to the relevant rest endpoint bean ?
>>>>>>>
>>>>>>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi Nirmal,
>>>>>>>>
>>>>>>>> But it works in get deployment policy endpoint, so it can not be a
>>>>>>>> limitation ?
>>>>>>>>
>>>>>>>> curl -X GET -H "Content-Type: application/json" -d
>>>>>>>> @'app-php-only.json' -k   -u admin:admin
>>>>>>>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>>>>>>>> | python -m json.tool
>>>>>>>>   % Total    % Received % Xferd  Average Speed   Time    Time
>>>>>>>> Time  Current
>>>>>>>>                                  Dload  Upload   Total   Spent
>>>>>>>>  Left  Speed
>>>>>>>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:--
>>>>>>>> --:--:--  8538
>>>>>>>> {
>>>>>>>>     "deploymentPolicy": {
>>>>>>>>         "id": "economyDeploymentPolicy",
>>>>>>>>         "partitionGroup": [
>>>>>>>>             {
>>>>>>>>                 "id": "ec2",
>>>>>>>>                 *"partition": [*
>>>>>>>> *                    {*
>>>>>>>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>>>>>>>> *                        "isPublic": false,*
>>>>>>>> *                        "partitionMax": 3,*
>>>>>>>> *                        "partitionMin": 1,*
>>>>>>>> *                        "property": [*
>>>>>>>> *                            {*
>>>>>>>> *                                "name": "region",*
>>>>>>>> *                                "value": "ap-southeast-1"*
>>>>>>>> *                            },*
>>>>>>>> *                            {*
>>>>>>>> *                                "name": "zone",*
>>>>>>>> *                                "value": "ap-southeast-1a"*
>>>>>>>> *                            }*
>>>>>>>> *                        ],*
>>>>>>>> *                        "provider": "ec2"*
>>>>>>>> *                    }*
>>>>>>>> *                ],*
>>>>>>>>                 "partitionAlgo": "one-after-another"
>>>>>>>>             }
>>>>>>>>         ],
>>>>>>>>         "public": false
>>>>>>>>     }
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>>>>>>>> now cartridges are shown as arrays.
>>>>>>>>> <value>cartridges</value>
>>>>>>>>>
>>>>>>>>> But we can't specify it for each variable.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> When I execute the GET serviceGroup Stratos endpoint I get the
>>>>>>>>>> folowing output in two different groups. Please note cartridges text  in
>>>>>>>>>> bold. When there are only one cartridge, it shows as a String (output1),
>>>>>>>>>> when there are multiple cartridges it is shown as an array (output2).
>>>>>>>>>>
>>>>>>>>>> But when I convert the object to a json text, it shows as arrays
>>>>>>>>>> even when there are single cartridge.
>>>>>>>>>>
>>>>>>>>>> The issue happens when the object is sent in response as below
>>>>>>>>>>
>>>>>>>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> In the code carridges is set as a list.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.
>>>>>>>>>>    asList(cartridges));
>>>>>>>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>>>>>>>> I tried doing it too. But same result.
>>>>>>>>>>
>>>>>>>>>> What is the reason for this?
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> output [1]
>>>>>>>>>>
>>>>>>>>>> {
>>>>>>>>>>     "serviceGroup": [
>>>>>>>>>>         {
>>>>>>>>>>            * "cartridges": "tomcat",*
>>>>>>>>>>             "dependencies": {
>>>>>>>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>>>>>>>             },
>>>>>>>>>>             "name": "group5",
>>>>>>>>>>             "subGroups": "group1"
>>>>>>>>>>         }
>>>>>>>>>>     ]
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> output [2]
>>>>>>>>>>
>>>>>>>>>> {
>>>>>>>>>>     "serviceGroup": {
>>>>>>>>>>         "cartridges": *[*
>>>>>>>>>> *            "tomcat",*
>>>>>>>>>> *            "php"*
>>>>>>>>>> *        ],*
>>>>>>>>>>         "dependencies": {
>>>>>>>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>>>>             "terminationBehaviour": "terminate-dependents"
>>>>>>>>>>         },
>>>>>>>>>>         "name": "group6",
>>>>>>>>>>         "subGroups": "group2"
>>>>>>>>>>     }
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> [1]
>>>>>>>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>>>>>>>> --
>>>>>>>>>>
>>>>>>>>>> Udara Liyanage
>>>>>>>>>> Software Engineer
>>>>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>>>>> lean. enterprise. middleware
>>>>>>>>>>
>>>>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>>>>> phone: +94 71 443 6897
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> Udara Liyanage
>>>>>>>>> Software Engineer
>>>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>>>> lean. enterprise. middleware
>>>>>>>>>
>>>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>>>> phone: +94 71 443 6897
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>>
>>>>>>>> Udara Liyanage
>>>>>>>> Software Engineer
>>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>>> lean. enterprise. middleware
>>>>>>>>
>>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>>> phone: +94 71 443 6897
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Best Regards,
>>>>>>> Nirmal
>>>>>>>
>>>>>>> Nirmal Fernando.
>>>>>>> PPMC Member & Committer of Apache Stratos,
>>>>>>> Senior Software Engineer, WSO2 Inc.
>>>>>>>
>>>>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>>
>>>>>> Udara Liyanage
>>>>>> Software Engineer
>>>>>> WSO2, Inc.: http://wso2.com
>>>>>> lean. enterprise. middleware
>>>>>>
>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>> phone: +94 71 443 6897
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Best Regards,
>>>>> Nirmal
>>>>>
>>>>> Nirmal Fernando.
>>>>> PPMC Member & Committer of Apache Stratos,
>>>>> Senior Software Engineer, WSO2 Inc.
>>>>>
>>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Udara Liyanage
>>>> Software Engineer
>>>> WSO2, Inc.: http://wso2.com
>>>> lean. enterprise. middleware
>>>>
>>>> web: http://udaraliyanage.wordpress.com
>>>> phone: +94 71 443 6897
>>>>
>>>
>>>
>>>
>>> --
>>> Best Regards,
>>> Nirmal
>>>
>>> Nirmal Fernando.
>>> PPMC Member & Committer of Apache Stratos,
>>> Senior Software Engineer, WSO2 Inc.
>>>
>>> Blog: http://nirmalfdo.blogspot.com/
>>>
>>
>>
>>
>> --
>>
>> Udara Liyanage
>> Software Engineer
>> WSO2, Inc.: http://wso2.com
>> lean. enterprise. middleware
>>
>> web: http://udaraliyanage.wordpress.com
>> phone: +94 71 443 6897
>>
>
>
>
> --
> Regards,
> Manula Chathurika Thantriwatte
> Software Engineer
> WSO2 Inc. : http://wso2.com
> lean . enterprise . middleware
>
> email : manulac@wso2.com / manula@apache.org
> phone : +94 772492511
> blog : http://manulachathurika.blogspot.com/
>
>
>
>


-- 

Udara Liyanage
Software Engineer
WSO2, Inc.: http://wso2.com
lean. enterprise. middleware

web: http://udaraliyanage.wordpress.com
phone: +94 71 443 6897

Re: Json response shows arrays as string when there are single value

Posted by Manula Chathurika Thantriwatte <ma...@wso2.com>.
Hi Udara,

Have you commit the changes.

On Wed, Nov 5, 2014 at 8:16 PM, Udara Liyanage <ud...@wso2.com> wrote:

> Hi Nirmal,
>
> Yes I already changed some endpoints which seems to work fine. I will test
> others and will update the thread.
>
> On Wed, Nov 5, 2014 at 8:08 PM, Nirmal Fernando <ni...@gmail.com>
> wrote:
>
>>
>>
>> On Wed, Nov 5, 2014 at 3:31 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>
>>> Hi,
>>>
>>> It works when I changed the Json provider to
>>> org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
>>>
>>>
>>> <bean id="jsonProvider"
>>> class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider">
>>>
>>
>> Yes, this is what I meant. It's a limitation of the earlier library we
>> used. +1 from me for this change, but please test all operations.
>>
>>     </bean>
>>>
>>> If we are using the above provider we do not need to specify
>>> serializeAsArray for any property as we have now.  In addition it
>>> automatically remove the root element. I pasted the existing JsonProvider
>>> configurations below.
>>>
>>>     <bean id="jsonProvider"
>>> class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>>>         <property name="supportUnwrapped" value="true"/>
>>>         <property name="serializeAsArray" value="true"/>
>>>         <property name="arrayKeys">
>>>             <list>
>>>                 <value>partitions</value>
>>>                 <value>property</value>
>>>                 <value>hostNames</value>
>>>                 <value>memberMap</value>
>>>                 <value>portMap</value>
>>>                 <value>partitionGroup</value>
>>>                 <value>member</value>
>>>                 <value>hostNames</value>
>>>                 <value>portMappings</value>
>>>                 <value>volumes</value>
>>>                 <value>domains</value>
>>>                 <value>kubernetesHost</value>
>>>                 <value>cartridges</value>
>>>             </list>
>>>         </property>
>>>     </bean>
>>> -->
>>>
>>>
>>> On Wed, Nov 5, 2014 at 7:53 PM, Nirmal Fernando <ni...@gmail.com>
>>> wrote:
>>>
>>>> May be we have to use element wrapper; @XmlElementWrapper(name=
>>>> "cartridges")
>>>>
>>>> http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html
>>>>
>>>> On Wed, Nov 5, 2014 at 3:11 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> You can find it [1]. Please note that other bean classes have public
>>>>> variables which are set when converting to a pojo. This bean as private
>>>>> variables and public getters and setters.
>>>>>
>>>>> [1]
>>>>> https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java
>>>>>
>>>>> On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <
>>>>> nirmal070125@gmail.com> wrote:
>>>>>
>>>>>> Can you point to the relevant rest endpoint bean ?
>>>>>>
>>>>>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi Nirmal,
>>>>>>>
>>>>>>> But it works in get deployment policy endpoint, so it can not be a
>>>>>>> limitation ?
>>>>>>>
>>>>>>> curl -X GET -H "Content-Type: application/json" -d
>>>>>>> @'app-php-only.json' -k   -u admin:admin
>>>>>>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>>>>>>> | python -m json.tool
>>>>>>>   % Total    % Received % Xferd  Average Speed   Time    Time
>>>>>>> Time  Current
>>>>>>>                                  Dload  Upload   Total   Spent
>>>>>>>  Left  Speed
>>>>>>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:--
>>>>>>> --:--:--  8538
>>>>>>> {
>>>>>>>     "deploymentPolicy": {
>>>>>>>         "id": "economyDeploymentPolicy",
>>>>>>>         "partitionGroup": [
>>>>>>>             {
>>>>>>>                 "id": "ec2",
>>>>>>>                 *"partition": [*
>>>>>>> *                    {*
>>>>>>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>>>>>>> *                        "isPublic": false,*
>>>>>>> *                        "partitionMax": 3,*
>>>>>>> *                        "partitionMin": 1,*
>>>>>>> *                        "property": [*
>>>>>>> *                            {*
>>>>>>> *                                "name": "region",*
>>>>>>> *                                "value": "ap-southeast-1"*
>>>>>>> *                            },*
>>>>>>> *                            {*
>>>>>>> *                                "name": "zone",*
>>>>>>> *                                "value": "ap-southeast-1a"*
>>>>>>> *                            }*
>>>>>>> *                        ],*
>>>>>>> *                        "provider": "ec2"*
>>>>>>> *                    }*
>>>>>>> *                ],*
>>>>>>>                 "partitionAlgo": "one-after-another"
>>>>>>>             }
>>>>>>>         ],
>>>>>>>         "public": false
>>>>>>>     }
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>>>>>>> now cartridges are shown as arrays.
>>>>>>>> <value>cartridges</value>
>>>>>>>>
>>>>>>>> But we can't specify it for each variable.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> When I execute the GET serviceGroup Stratos endpoint I get the
>>>>>>>>> folowing output in two different groups. Please note cartridges text  in
>>>>>>>>> bold. When there are only one cartridge, it shows as a String (output1),
>>>>>>>>> when there are multiple cartridges it is shown as an array (output2).
>>>>>>>>>
>>>>>>>>> But when I convert the object to a json text, it shows as arrays
>>>>>>>>> even when there are single cartridge.
>>>>>>>>>
>>>>>>>>> The issue happens when the object is sent in response as below
>>>>>>>>>
>>>>>>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> In the code carridges is set as a list.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.
>>>>>>>>>    asList(cartridges));
>>>>>>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>>>>>>> I tried doing it too. But same result.
>>>>>>>>>
>>>>>>>>> What is the reason for this?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> output [1]
>>>>>>>>>
>>>>>>>>> {
>>>>>>>>>     "serviceGroup": [
>>>>>>>>>         {
>>>>>>>>>            * "cartridges": "tomcat",*
>>>>>>>>>             "dependencies": {
>>>>>>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>>>>>>             },
>>>>>>>>>             "name": "group5",
>>>>>>>>>             "subGroups": "group1"
>>>>>>>>>         }
>>>>>>>>>     ]
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> output [2]
>>>>>>>>>
>>>>>>>>> {
>>>>>>>>>     "serviceGroup": {
>>>>>>>>>         "cartridges": *[*
>>>>>>>>> *            "tomcat",*
>>>>>>>>> *            "php"*
>>>>>>>>> *        ],*
>>>>>>>>>         "dependencies": {
>>>>>>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>>>             "terminationBehaviour": "terminate-dependents"
>>>>>>>>>         },
>>>>>>>>>         "name": "group6",
>>>>>>>>>         "subGroups": "group2"
>>>>>>>>>     }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> [1]
>>>>>>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> Udara Liyanage
>>>>>>>>> Software Engineer
>>>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>>>> lean. enterprise. middleware
>>>>>>>>>
>>>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>>>> phone: +94 71 443 6897
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>>
>>>>>>>> Udara Liyanage
>>>>>>>> Software Engineer
>>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>>> lean. enterprise. middleware
>>>>>>>>
>>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>>> phone: +94 71 443 6897
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>> Udara Liyanage
>>>>>>> Software Engineer
>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>> lean. enterprise. middleware
>>>>>>>
>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>> phone: +94 71 443 6897
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Best Regards,
>>>>>> Nirmal
>>>>>>
>>>>>> Nirmal Fernando.
>>>>>> PPMC Member & Committer of Apache Stratos,
>>>>>> Senior Software Engineer, WSO2 Inc.
>>>>>>
>>>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Udara Liyanage
>>>>> Software Engineer
>>>>> WSO2, Inc.: http://wso2.com
>>>>> lean. enterprise. middleware
>>>>>
>>>>> web: http://udaraliyanage.wordpress.com
>>>>> phone: +94 71 443 6897
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Best Regards,
>>>> Nirmal
>>>>
>>>> Nirmal Fernando.
>>>> PPMC Member & Committer of Apache Stratos,
>>>> Senior Software Engineer, WSO2 Inc.
>>>>
>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Udara Liyanage
>>> Software Engineer
>>> WSO2, Inc.: http://wso2.com
>>> lean. enterprise. middleware
>>>
>>> web: http://udaraliyanage.wordpress.com
>>> phone: +94 71 443 6897
>>>
>>
>>
>>
>> --
>> Best Regards,
>> Nirmal
>>
>> Nirmal Fernando.
>> PPMC Member & Committer of Apache Stratos,
>> Senior Software Engineer, WSO2 Inc.
>>
>> Blog: http://nirmalfdo.blogspot.com/
>>
>
>
>
> --
>
> Udara Liyanage
> Software Engineer
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
>
> web: http://udaraliyanage.wordpress.com
> phone: +94 71 443 6897
>



-- 
Regards,
Manula Chathurika Thantriwatte
Software Engineer
WSO2 Inc. : http://wso2.com
lean . enterprise . middleware

email : manulac@wso2.com / manula@apache.org
phone : +94 772492511
blog : http://manulachathurika.blogspot.com/

Re: Json response shows arrays as string when there are single value

Posted by Udara Liyanage <ud...@wso2.com>.
Hi Nirmal,

Yes I already changed some endpoints which seems to work fine. I will test
others and will update the thread.

On Wed, Nov 5, 2014 at 8:08 PM, Nirmal Fernando <ni...@gmail.com>
wrote:

>
>
> On Wed, Nov 5, 2014 at 3:31 PM, Udara Liyanage <ud...@wso2.com> wrote:
>
>> Hi,
>>
>> It works when I changed the Json provider to
>> org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
>>
>>
>> <bean id="jsonProvider"
>> class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider">
>>
>
> Yes, this is what I meant. It's a limitation of the earlier library we
> used. +1 from me for this change, but please test all operations.
>
>     </bean>
>>
>> If we are using the above provider we do not need to specify
>> serializeAsArray for any property as we have now.  In addition it
>> automatically remove the root element. I pasted the existing JsonProvider
>> configurations below.
>>
>>     <bean id="jsonProvider"
>> class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>>         <property name="supportUnwrapped" value="true"/>
>>         <property name="serializeAsArray" value="true"/>
>>         <property name="arrayKeys">
>>             <list>
>>                 <value>partitions</value>
>>                 <value>property</value>
>>                 <value>hostNames</value>
>>                 <value>memberMap</value>
>>                 <value>portMap</value>
>>                 <value>partitionGroup</value>
>>                 <value>member</value>
>>                 <value>hostNames</value>
>>                 <value>portMappings</value>
>>                 <value>volumes</value>
>>                 <value>domains</value>
>>                 <value>kubernetesHost</value>
>>                 <value>cartridges</value>
>>             </list>
>>         </property>
>>     </bean>
>> -->
>>
>>
>> On Wed, Nov 5, 2014 at 7:53 PM, Nirmal Fernando <ni...@gmail.com>
>> wrote:
>>
>>> May be we have to use element wrapper; @XmlElementWrapper(name=
>>> "cartridges")
>>>
>>> http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html
>>>
>>> On Wed, Nov 5, 2014 at 3:11 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> You can find it [1]. Please note that other bean classes have public
>>>> variables which are set when converting to a pojo. This bean as private
>>>> variables and public getters and setters.
>>>>
>>>> [1]
>>>> https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java
>>>>
>>>> On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <nirmal070125@gmail.com
>>>> > wrote:
>>>>
>>>>> Can you point to the relevant rest endpoint bean ?
>>>>>
>>>>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>>
>>>>>> Hi Nirmal,
>>>>>>
>>>>>> But it works in get deployment policy endpoint, so it can not be a
>>>>>> limitation ?
>>>>>>
>>>>>> curl -X GET -H "Content-Type: application/json" -d
>>>>>> @'app-php-only.json' -k   -u admin:admin
>>>>>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>>>>>> | python -m json.tool
>>>>>>   % Total    % Received % Xferd  Average Speed   Time    Time
>>>>>> Time  Current
>>>>>>                                  Dload  Upload   Total   Spent
>>>>>>  Left  Speed
>>>>>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:--
>>>>>> --:--:--  8538
>>>>>> {
>>>>>>     "deploymentPolicy": {
>>>>>>         "id": "economyDeploymentPolicy",
>>>>>>         "partitionGroup": [
>>>>>>             {
>>>>>>                 "id": "ec2",
>>>>>>                 *"partition": [*
>>>>>> *                    {*
>>>>>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>>>>>> *                        "isPublic": false,*
>>>>>> *                        "partitionMax": 3,*
>>>>>> *                        "partitionMin": 1,*
>>>>>> *                        "property": [*
>>>>>> *                            {*
>>>>>> *                                "name": "region",*
>>>>>> *                                "value": "ap-southeast-1"*
>>>>>> *                            },*
>>>>>> *                            {*
>>>>>> *                                "name": "zone",*
>>>>>> *                                "value": "ap-southeast-1a"*
>>>>>> *                            }*
>>>>>> *                        ],*
>>>>>> *                        "provider": "ec2"*
>>>>>> *                    }*
>>>>>> *                ],*
>>>>>>                 "partitionAlgo": "one-after-another"
>>>>>>             }
>>>>>>         ],
>>>>>>         "public": false
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>>
>>>>>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>>>>>> now cartridges are shown as arrays.
>>>>>>> <value>cartridges</value>
>>>>>>>
>>>>>>> But we can't specify it for each variable.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> When I execute the GET serviceGroup Stratos endpoint I get the
>>>>>>>> folowing output in two different groups. Please note cartridges text  in
>>>>>>>> bold. When there are only one cartridge, it shows as a String (output1),
>>>>>>>> when there are multiple cartridges it is shown as an array (output2).
>>>>>>>>
>>>>>>>> But when I convert the object to a json text, it shows as arrays
>>>>>>>> even when there are single cartridge.
>>>>>>>>
>>>>>>>> The issue happens when the object is sent in response as below
>>>>>>>>
>>>>>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>>>>>
>>>>>>>>
>>>>>>>> In the code carridges is set as a list.
>>>>>>>>
>>>>>>>>
>>>>>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.
>>>>>>>>    asList(cartridges));
>>>>>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>>>>>
>>>>>>>>
>>>>>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>>>>>> I tried doing it too. But same result.
>>>>>>>>
>>>>>>>> What is the reason for this?
>>>>>>>>
>>>>>>>>
>>>>>>>> output [1]
>>>>>>>>
>>>>>>>> {
>>>>>>>>     "serviceGroup": [
>>>>>>>>         {
>>>>>>>>            * "cartridges": "tomcat",*
>>>>>>>>             "dependencies": {
>>>>>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>>>>>             },
>>>>>>>>             "name": "group5",
>>>>>>>>             "subGroups": "group1"
>>>>>>>>         }
>>>>>>>>     ]
>>>>>>>> }
>>>>>>>>
>>>>>>>> output [2]
>>>>>>>>
>>>>>>>> {
>>>>>>>>     "serviceGroup": {
>>>>>>>>         "cartridges": *[*
>>>>>>>> *            "tomcat",*
>>>>>>>> *            "php"*
>>>>>>>> *        ],*
>>>>>>>>         "dependencies": {
>>>>>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>>             "terminationBehaviour": "terminate-dependents"
>>>>>>>>         },
>>>>>>>>         "name": "group6",
>>>>>>>>         "subGroups": "group2"
>>>>>>>>     }
>>>>>>>> }
>>>>>>>>
>>>>>>>> [1]
>>>>>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>>>>>> --
>>>>>>>>
>>>>>>>> Udara Liyanage
>>>>>>>> Software Engineer
>>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>>> lean. enterprise. middleware
>>>>>>>>
>>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>>> phone: +94 71 443 6897
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>> Udara Liyanage
>>>>>>> Software Engineer
>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>> lean. enterprise. middleware
>>>>>>>
>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>> phone: +94 71 443 6897
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>>
>>>>>> Udara Liyanage
>>>>>> Software Engineer
>>>>>> WSO2, Inc.: http://wso2.com
>>>>>> lean. enterprise. middleware
>>>>>>
>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>> phone: +94 71 443 6897
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Best Regards,
>>>>> Nirmal
>>>>>
>>>>> Nirmal Fernando.
>>>>> PPMC Member & Committer of Apache Stratos,
>>>>> Senior Software Engineer, WSO2 Inc.
>>>>>
>>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Udara Liyanage
>>>> Software Engineer
>>>> WSO2, Inc.: http://wso2.com
>>>> lean. enterprise. middleware
>>>>
>>>> web: http://udaraliyanage.wordpress.com
>>>> phone: +94 71 443 6897
>>>>
>>>
>>>
>>>
>>> --
>>> Best Regards,
>>> Nirmal
>>>
>>> Nirmal Fernando.
>>> PPMC Member & Committer of Apache Stratos,
>>> Senior Software Engineer, WSO2 Inc.
>>>
>>> Blog: http://nirmalfdo.blogspot.com/
>>>
>>
>>
>>
>> --
>>
>> Udara Liyanage
>> Software Engineer
>> WSO2, Inc.: http://wso2.com
>> lean. enterprise. middleware
>>
>> web: http://udaraliyanage.wordpress.com
>> phone: +94 71 443 6897
>>
>
>
>
> --
> Best Regards,
> Nirmal
>
> Nirmal Fernando.
> PPMC Member & Committer of Apache Stratos,
> Senior Software Engineer, WSO2 Inc.
>
> Blog: http://nirmalfdo.blogspot.com/
>



-- 

Udara Liyanage
Software Engineer
WSO2, Inc.: http://wso2.com
lean. enterprise. middleware

web: http://udaraliyanage.wordpress.com
phone: +94 71 443 6897

Re: Json response shows arrays as string when there are single value

Posted by Nirmal Fernando <ni...@gmail.com>.
On Wed, Nov 5, 2014 at 3:31 PM, Udara Liyanage <ud...@wso2.com> wrote:

> Hi,
>
> It works when I changed the Json provider to
> org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
>
>
> <bean id="jsonProvider"
> class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider">
>

Yes, this is what I meant. It's a limitation of the earlier library we
used. +1 from me for this change, but please test all operations.

    </bean>
>
> If we are using the above provider we do not need to specify
> serializeAsArray for any property as we have now.  In addition it
> automatically remove the root element. I pasted the existing JsonProvider
> configurations below.
>
>     <bean id="jsonProvider"
> class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>         <property name="supportUnwrapped" value="true"/>
>         <property name="serializeAsArray" value="true"/>
>         <property name="arrayKeys">
>             <list>
>                 <value>partitions</value>
>                 <value>property</value>
>                 <value>hostNames</value>
>                 <value>memberMap</value>
>                 <value>portMap</value>
>                 <value>partitionGroup</value>
>                 <value>member</value>
>                 <value>hostNames</value>
>                 <value>portMappings</value>
>                 <value>volumes</value>
>                 <value>domains</value>
>                 <value>kubernetesHost</value>
>                 <value>cartridges</value>
>             </list>
>         </property>
>     </bean>
> -->
>
>
> On Wed, Nov 5, 2014 at 7:53 PM, Nirmal Fernando <ni...@gmail.com>
> wrote:
>
>> May be we have to use element wrapper; @XmlElementWrapper(name=
>> "cartridges")
>>
>> http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html
>>
>> On Wed, Nov 5, 2014 at 3:11 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>
>>> Hi,
>>>
>>> You can find it [1]. Please note that other bean classes have public
>>> variables which are set when converting to a pojo. This bean as private
>>> variables and public getters and setters.
>>>
>>> [1]
>>> https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java
>>>
>>> On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <ni...@gmail.com>
>>> wrote:
>>>
>>>> Can you point to the relevant rest endpoint bean ?
>>>>
>>>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>
>>>>> Hi Nirmal,
>>>>>
>>>>> But it works in get deployment policy endpoint, so it can not be a
>>>>> limitation ?
>>>>>
>>>>> curl -X GET -H "Content-Type: application/json" -d
>>>>> @'app-php-only.json' -k   -u admin:admin
>>>>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>>>>> | python -m json.tool
>>>>>   % Total    % Received % Xferd  Average Speed   Time    Time     Time
>>>>>  Current
>>>>>                                  Dload  Upload   Total   Spent    Left
>>>>>  Speed
>>>>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:--
>>>>> --:--:--  8538
>>>>> {
>>>>>     "deploymentPolicy": {
>>>>>         "id": "economyDeploymentPolicy",
>>>>>         "partitionGroup": [
>>>>>             {
>>>>>                 "id": "ec2",
>>>>>                 *"partition": [*
>>>>> *                    {*
>>>>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>>>>> *                        "isPublic": false,*
>>>>> *                        "partitionMax": 3,*
>>>>> *                        "partitionMin": 1,*
>>>>> *                        "property": [*
>>>>> *                            {*
>>>>> *                                "name": "region",*
>>>>> *                                "value": "ap-southeast-1"*
>>>>> *                            },*
>>>>> *                            {*
>>>>> *                                "name": "zone",*
>>>>> *                                "value": "ap-southeast-1a"*
>>>>> *                            }*
>>>>> *                        ],*
>>>>> *                        "provider": "ec2"*
>>>>> *                    }*
>>>>> *                ],*
>>>>>                 "partitionAlgo": "one-after-another"
>>>>>             }
>>>>>         ],
>>>>>         "public": false
>>>>>     }
>>>>> }
>>>>>
>>>>>
>>>>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>>>>> now cartridges are shown as arrays.
>>>>>> <value>cartridges</value>
>>>>>>
>>>>>> But we can't specify it for each variable.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> When I execute the GET serviceGroup Stratos endpoint I get the
>>>>>>> folowing output in two different groups. Please note cartridges text  in
>>>>>>> bold. When there are only one cartridge, it shows as a String (output1),
>>>>>>> when there are multiple cartridges it is shown as an array (output2).
>>>>>>>
>>>>>>> But when I convert the object to a json text, it shows as arrays
>>>>>>> even when there are single cartridge.
>>>>>>>
>>>>>>> The issue happens when the object is sent in response as below
>>>>>>>
>>>>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>>>>
>>>>>>>
>>>>>>> In the code carridges is set as a list.
>>>>>>>
>>>>>>>
>>>>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.
>>>>>>>    asList(cartridges));
>>>>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>>>>
>>>>>>>
>>>>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>>>>> I tried doing it too. But same result.
>>>>>>>
>>>>>>> What is the reason for this?
>>>>>>>
>>>>>>>
>>>>>>> output [1]
>>>>>>>
>>>>>>> {
>>>>>>>     "serviceGroup": [
>>>>>>>         {
>>>>>>>            * "cartridges": "tomcat",*
>>>>>>>             "dependencies": {
>>>>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>>>>             },
>>>>>>>             "name": "group5",
>>>>>>>             "subGroups": "group1"
>>>>>>>         }
>>>>>>>     ]
>>>>>>> }
>>>>>>>
>>>>>>> output [2]
>>>>>>>
>>>>>>> {
>>>>>>>     "serviceGroup": {
>>>>>>>         "cartridges": *[*
>>>>>>> *            "tomcat",*
>>>>>>> *            "php"*
>>>>>>> *        ],*
>>>>>>>         "dependencies": {
>>>>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>>             "terminationBehaviour": "terminate-dependents"
>>>>>>>         },
>>>>>>>         "name": "group6",
>>>>>>>         "subGroups": "group2"
>>>>>>>     }
>>>>>>> }
>>>>>>>
>>>>>>> [1]
>>>>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>>>>> --
>>>>>>>
>>>>>>> Udara Liyanage
>>>>>>> Software Engineer
>>>>>>> WSO2, Inc.: http://wso2.com
>>>>>>> lean. enterprise. middleware
>>>>>>>
>>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>>> phone: +94 71 443 6897
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>>
>>>>>> Udara Liyanage
>>>>>> Software Engineer
>>>>>> WSO2, Inc.: http://wso2.com
>>>>>> lean. enterprise. middleware
>>>>>>
>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>> phone: +94 71 443 6897
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Udara Liyanage
>>>>> Software Engineer
>>>>> WSO2, Inc.: http://wso2.com
>>>>> lean. enterprise. middleware
>>>>>
>>>>> web: http://udaraliyanage.wordpress.com
>>>>> phone: +94 71 443 6897
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Best Regards,
>>>> Nirmal
>>>>
>>>> Nirmal Fernando.
>>>> PPMC Member & Committer of Apache Stratos,
>>>> Senior Software Engineer, WSO2 Inc.
>>>>
>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Udara Liyanage
>>> Software Engineer
>>> WSO2, Inc.: http://wso2.com
>>> lean. enterprise. middleware
>>>
>>> web: http://udaraliyanage.wordpress.com
>>> phone: +94 71 443 6897
>>>
>>
>>
>>
>> --
>> Best Regards,
>> Nirmal
>>
>> Nirmal Fernando.
>> PPMC Member & Committer of Apache Stratos,
>> Senior Software Engineer, WSO2 Inc.
>>
>> Blog: http://nirmalfdo.blogspot.com/
>>
>
>
>
> --
>
> Udara Liyanage
> Software Engineer
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
>
> web: http://udaraliyanage.wordpress.com
> phone: +94 71 443 6897
>



-- 
Best Regards,
Nirmal

Nirmal Fernando.
PPMC Member & Committer of Apache Stratos,
Senior Software Engineer, WSO2 Inc.

Blog: http://nirmalfdo.blogspot.com/

Re: Json response shows arrays as string when there are single value

Posted by Udara Liyanage <ud...@wso2.com>.
Hi,

It works when I changed the Json provider to
org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider


<bean id="jsonProvider"
class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider">
    </bean>

If we are using the above provider we do not need to specify
serializeAsArray for any property as we have now.  In addition it
automatically remove the root element. I pasted the existing JsonProvider
configurations below.

    <bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
        <property name="supportUnwrapped" value="true"/>
        <property name="serializeAsArray" value="true"/>
        <property name="arrayKeys">
            <list>
                <value>partitions</value>
                <value>property</value>
                <value>hostNames</value>
                <value>memberMap</value>
                <value>portMap</value>
                <value>partitionGroup</value>
                <value>member</value>
                <value>hostNames</value>
                <value>portMappings</value>
                <value>volumes</value>
                <value>domains</value>
                <value>kubernetesHost</value>
                <value>cartridges</value>
            </list>
        </property>
    </bean>
-->


On Wed, Nov 5, 2014 at 7:53 PM, Nirmal Fernando <ni...@gmail.com>
wrote:

> May be we have to use element wrapper; @XmlElementWrapper(name=
> "cartridges")
>
> http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html
>
> On Wed, Nov 5, 2014 at 3:11 PM, Udara Liyanage <ud...@wso2.com> wrote:
>
>> Hi,
>>
>> You can find it [1]. Please note that other bean classes have public
>> variables which are set when converting to a pojo. This bean as private
>> variables and public getters and setters.
>>
>> [1]
>> https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java
>>
>> On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <ni...@gmail.com>
>> wrote:
>>
>>> Can you point to the relevant rest endpoint bean ?
>>>
>>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>
>>>> Hi Nirmal,
>>>>
>>>> But it works in get deployment policy endpoint, so it can not be a
>>>> limitation ?
>>>>
>>>> curl -X GET -H "Content-Type: application/json" -d @'app-php-only.json'
>>>> -k   -u admin:admin
>>>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>>>> | python -m json.tool
>>>>   % Total    % Received % Xferd  Average Speed   Time    Time     Time
>>>>  Current
>>>>                                  Dload  Upload   Total   Spent    Left
>>>>  Speed
>>>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:--
>>>> --:--:--  8538
>>>> {
>>>>     "deploymentPolicy": {
>>>>         "id": "economyDeploymentPolicy",
>>>>         "partitionGroup": [
>>>>             {
>>>>                 "id": "ec2",
>>>>                 *"partition": [*
>>>> *                    {*
>>>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>>>> *                        "isPublic": false,*
>>>> *                        "partitionMax": 3,*
>>>> *                        "partitionMin": 1,*
>>>> *                        "property": [*
>>>> *                            {*
>>>> *                                "name": "region",*
>>>> *                                "value": "ap-southeast-1"*
>>>> *                            },*
>>>> *                            {*
>>>> *                                "name": "zone",*
>>>> *                                "value": "ap-southeast-1a"*
>>>> *                            }*
>>>> *                        ],*
>>>> *                        "provider": "ec2"*
>>>> *                    }*
>>>> *                ],*
>>>>                 "partitionAlgo": "one-after-another"
>>>>             }
>>>>         ],
>>>>         "public": false
>>>>     }
>>>> }
>>>>
>>>>
>>>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>>>> now cartridges are shown as arrays.
>>>>> <value>cartridges</value>
>>>>>
>>>>> But we can't specify it for each variable.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> When I execute the GET serviceGroup Stratos endpoint I get the
>>>>>> folowing output in two different groups. Please note cartridges text  in
>>>>>> bold. When there are only one cartridge, it shows as a String (output1),
>>>>>> when there are multiple cartridges it is shown as an array (output2).
>>>>>>
>>>>>> But when I convert the object to a json text, it shows as arrays even
>>>>>> when there are single cartridge.
>>>>>>
>>>>>> The issue happens when the object is sent in response as below
>>>>>>
>>>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>>>
>>>>>>
>>>>>> In the code carridges is set as a list.
>>>>>>
>>>>>>
>>>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.
>>>>>>    asList(cartridges));
>>>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>>>
>>>>>>
>>>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>>>> I tried doing it too. But same result.
>>>>>>
>>>>>> What is the reason for this?
>>>>>>
>>>>>>
>>>>>> output [1]
>>>>>>
>>>>>> {
>>>>>>     "serviceGroup": [
>>>>>>         {
>>>>>>            * "cartridges": "tomcat",*
>>>>>>             "dependencies": {
>>>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>>>             },
>>>>>>             "name": "group5",
>>>>>>             "subGroups": "group1"
>>>>>>         }
>>>>>>     ]
>>>>>> }
>>>>>>
>>>>>> output [2]
>>>>>>
>>>>>> {
>>>>>>     "serviceGroup": {
>>>>>>         "cartridges": *[*
>>>>>> *            "tomcat",*
>>>>>> *            "php"*
>>>>>> *        ],*
>>>>>>         "dependencies": {
>>>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>             "terminationBehaviour": "terminate-dependents"
>>>>>>         },
>>>>>>         "name": "group6",
>>>>>>         "subGroups": "group2"
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>> [1]
>>>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>>>> --
>>>>>>
>>>>>> Udara Liyanage
>>>>>> Software Engineer
>>>>>> WSO2, Inc.: http://wso2.com
>>>>>> lean. enterprise. middleware
>>>>>>
>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>> phone: +94 71 443 6897
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Udara Liyanage
>>>>> Software Engineer
>>>>> WSO2, Inc.: http://wso2.com
>>>>> lean. enterprise. middleware
>>>>>
>>>>> web: http://udaraliyanage.wordpress.com
>>>>> phone: +94 71 443 6897
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Udara Liyanage
>>>> Software Engineer
>>>> WSO2, Inc.: http://wso2.com
>>>> lean. enterprise. middleware
>>>>
>>>> web: http://udaraliyanage.wordpress.com
>>>> phone: +94 71 443 6897
>>>>
>>>
>>>
>>>
>>> --
>>> Best Regards,
>>> Nirmal
>>>
>>> Nirmal Fernando.
>>> PPMC Member & Committer of Apache Stratos,
>>> Senior Software Engineer, WSO2 Inc.
>>>
>>> Blog: http://nirmalfdo.blogspot.com/
>>>
>>
>>
>>
>> --
>>
>> Udara Liyanage
>> Software Engineer
>> WSO2, Inc.: http://wso2.com
>> lean. enterprise. middleware
>>
>> web: http://udaraliyanage.wordpress.com
>> phone: +94 71 443 6897
>>
>
>
>
> --
> Best Regards,
> Nirmal
>
> Nirmal Fernando.
> PPMC Member & Committer of Apache Stratos,
> Senior Software Engineer, WSO2 Inc.
>
> Blog: http://nirmalfdo.blogspot.com/
>



-- 

Udara Liyanage
Software Engineer
WSO2, Inc.: http://wso2.com
lean. enterprise. middleware

web: http://udaraliyanage.wordpress.com
phone: +94 71 443 6897

Re: Json response shows arrays as string when there are single value

Posted by Nirmal Fernando <ni...@gmail.com>.
May be we have to use element wrapper; @XmlElementWrapper(name="cartridges")

http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html

On Wed, Nov 5, 2014 at 3:11 PM, Udara Liyanage <ud...@wso2.com> wrote:

> Hi,
>
> You can find it [1]. Please note that other bean classes have public
> variables which are set when converting to a pojo. This bean as private
> variables and public getters and setters.
>
> [1]
> https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java
>
> On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <ni...@gmail.com>
> wrote:
>
>> Can you point to the relevant rest endpoint bean ?
>>
>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>
>>> Hi Nirmal,
>>>
>>> But it works in get deployment policy endpoint, so it can not be a
>>> limitation ?
>>>
>>> curl -X GET -H "Content-Type: application/json" -d @'app-php-only.json'
>>> -k   -u admin:admin
>>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>>> | python -m json.tool
>>>   % Total    % Received % Xferd  Average Speed   Time    Time     Time
>>>  Current
>>>                                  Dload  Upload   Total   Spent    Left
>>>  Speed
>>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:-- --:--:--
>>>  8538
>>> {
>>>     "deploymentPolicy": {
>>>         "id": "economyDeploymentPolicy",
>>>         "partitionGroup": [
>>>             {
>>>                 "id": "ec2",
>>>                 *"partition": [*
>>> *                    {*
>>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>>> *                        "isPublic": false,*
>>> *                        "partitionMax": 3,*
>>> *                        "partitionMin": 1,*
>>> *                        "property": [*
>>> *                            {*
>>> *                                "name": "region",*
>>> *                                "value": "ap-southeast-1"*
>>> *                            },*
>>> *                            {*
>>> *                                "name": "zone",*
>>> *                                "value": "ap-southeast-1a"*
>>> *                            }*
>>> *                        ],*
>>> *                        "provider": "ec2"*
>>> *                    }*
>>> *                ],*
>>>                 "partitionAlgo": "one-after-another"
>>>             }
>>>         ],
>>>         "public": false
>>>     }
>>> }
>>>
>>>
>>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>>> now cartridges are shown as arrays.
>>>> <value>cartridges</value>
>>>>
>>>> But we can't specify it for each variable.
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> When I execute the GET serviceGroup Stratos endpoint I get the
>>>>> folowing output in two different groups. Please note cartridges text  in
>>>>> bold. When there are only one cartridge, it shows as a String (output1),
>>>>> when there are multiple cartridges it is shown as an array (output2).
>>>>>
>>>>> But when I convert the object to a json text, it shows as arrays even
>>>>> when there are single cartridge.
>>>>>
>>>>> The issue happens when the object is sent in response as below
>>>>>
>>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>>
>>>>>
>>>>> In the code carridges is set as a list.
>>>>>
>>>>>
>>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.asList
>>>>>    (cartridges));
>>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>>
>>>>>
>>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>>> I tried doing it too. But same result.
>>>>>
>>>>> What is the reason for this?
>>>>>
>>>>>
>>>>> output [1]
>>>>>
>>>>> {
>>>>>     "serviceGroup": [
>>>>>         {
>>>>>            * "cartridges": "tomcat",*
>>>>>             "dependencies": {
>>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>>             },
>>>>>             "name": "group5",
>>>>>             "subGroups": "group1"
>>>>>         }
>>>>>     ]
>>>>> }
>>>>>
>>>>> output [2]
>>>>>
>>>>> {
>>>>>     "serviceGroup": {
>>>>>         "cartridges": *[*
>>>>> *            "tomcat",*
>>>>> *            "php"*
>>>>> *        ],*
>>>>>         "dependencies": {
>>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>>             "terminationBehaviour": "terminate-dependents"
>>>>>         },
>>>>>         "name": "group6",
>>>>>         "subGroups": "group2"
>>>>>     }
>>>>> }
>>>>>
>>>>> [1]
>>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>>> --
>>>>>
>>>>> Udara Liyanage
>>>>> Software Engineer
>>>>> WSO2, Inc.: http://wso2.com
>>>>> lean. enterprise. middleware
>>>>>
>>>>> web: http://udaraliyanage.wordpress.com
>>>>> phone: +94 71 443 6897
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Udara Liyanage
>>>> Software Engineer
>>>> WSO2, Inc.: http://wso2.com
>>>> lean. enterprise. middleware
>>>>
>>>> web: http://udaraliyanage.wordpress.com
>>>> phone: +94 71 443 6897
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Udara Liyanage
>>> Software Engineer
>>> WSO2, Inc.: http://wso2.com
>>> lean. enterprise. middleware
>>>
>>> web: http://udaraliyanage.wordpress.com
>>> phone: +94 71 443 6897
>>>
>>
>>
>>
>> --
>> Best Regards,
>> Nirmal
>>
>> Nirmal Fernando.
>> PPMC Member & Committer of Apache Stratos,
>> Senior Software Engineer, WSO2 Inc.
>>
>> Blog: http://nirmalfdo.blogspot.com/
>>
>
>
>
> --
>
> Udara Liyanage
> Software Engineer
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
>
> web: http://udaraliyanage.wordpress.com
> phone: +94 71 443 6897
>



-- 
Best Regards,
Nirmal

Nirmal Fernando.
PPMC Member & Committer of Apache Stratos,
Senior Software Engineer, WSO2 Inc.

Blog: http://nirmalfdo.blogspot.com/

Re: Json response shows arrays as string when there are single value

Posted by Manula Chathurika Thantriwatte <ma...@wso2.com>.
Hi Udara,

I have tried with the online JSON POJO converter [1] with the grouping
json. I get the following bean class for ServiceGroupDefinition. Currently
we have used list for cartridges, subGroups and staupOrders. I think this
should be change to String array. WDYT ?

public class ServiceGroupDefinition
{
    private Dependencies dependencies;

    private String name;

    private String[] subGroups;

    private String[] cartridges;

    public Dependencies getDependencies ()
    {
        return dependencies;
    }

    public void setDependencies (Dependencies dependencies)
    {
        this.dependencies = dependencies;
    }

    public String getName ()
    {
        return name;
    }

    public void setName (String name)
    {
        this.name = name;
    }

    public String[] getSubGroups ()
    {
        return subGroups;
    }

    public void setSubGroups (String[] subGroups)
    {
        this.subGroups = subGroups;
    }

    public String[] getCartridges ()
    {
        return cartridges;
    }

    public void setCartridges (String[] cartridges)
    {
        this.cartridges = cartridges;
    }
}


public class Dependencies
{
    private String terminationBehaviour;

    private String[] startupOrders;

    public String getTerminationBehaviour ()
    {
        return terminationBehaviour;
    }

    public void setTerminationBehaviour (String terminationBehaviour)
    {
        this.terminationBehaviour = terminationBehaviour;
    }

    public String[] getStartupOrders ()
    {
        return startupOrders;
    }

    public void setStartupOrders (String[] startupOrders)
    {
        this.startupOrders = startupOrders;
    }
}


[1] http://pojo.sodhanalibrary.com/

Thanks !

On Wed, Nov 5, 2014 at 7:55 PM, Manula Chathurika Thantriwatte <
manulac@wso2.com> wrote:

> Hi Udara,
>
> I think the POJO conversion didn't happen correctly. That's why it didn't
> deserialize correctly.
>
> On Wed, Nov 5, 2014 at 7:41 PM, Udara Liyanage <ud...@wso2.com> wrote:
>
>> Hi,
>>
>> You can find it [1]. Please note that other bean classes have public
>> variables which are set when converting to a pojo. This bean as private
>> variables and public getters and setters.
>>
>> [1]
>> https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java
>>
>> On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <ni...@gmail.com>
>> wrote:
>>
>>> Can you point to the relevant rest endpoint bean ?
>>>
>>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>
>>>> Hi Nirmal,
>>>>
>>>> But it works in get deployment policy endpoint, so it can not be a
>>>> limitation ?
>>>>
>>>> curl -X GET -H "Content-Type: application/json" -d @'app-php-only.json'
>>>> -k   -u admin:admin
>>>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>>>> | python -m json.tool
>>>>   % Total    % Received % Xferd  Average Speed   Time    Time     Time
>>>>  Current
>>>>                                  Dload  Upload   Total   Spent    Left
>>>>  Speed
>>>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:--
>>>> --:--:--  8538
>>>> {
>>>>     "deploymentPolicy": {
>>>>         "id": "economyDeploymentPolicy",
>>>>         "partitionGroup": [
>>>>             {
>>>>                 "id": "ec2",
>>>>                 *"partition": [*
>>>> *                    {*
>>>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>>>> *                        "isPublic": false,*
>>>> *                        "partitionMax": 3,*
>>>> *                        "partitionMin": 1,*
>>>> *                        "property": [*
>>>> *                            {*
>>>> *                                "name": "region",*
>>>> *                                "value": "ap-southeast-1"*
>>>> *                            },*
>>>> *                            {*
>>>> *                                "name": "zone",*
>>>> *                                "value": "ap-southeast-1a"*
>>>> *                            }*
>>>> *                        ],*
>>>> *                        "provider": "ec2"*
>>>> *                    }*
>>>> *                ],*
>>>>                 "partitionAlgo": "one-after-another"
>>>>             }
>>>>         ],
>>>>         "public": false
>>>>     }
>>>> }
>>>>
>>>>
>>>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>>>> now cartridges are shown as arrays.
>>>>> <value>cartridges</value>
>>>>>
>>>>> But we can't specify it for each variable.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> When I execute the GET serviceGroup Stratos endpoint I get the
>>>>>> folowing output in two different groups. Please note cartridges text  in
>>>>>> bold. When there are only one cartridge, it shows as a String (output1),
>>>>>> when there are multiple cartridges it is shown as an array (output2).
>>>>>>
>>>>>> But when I convert the object to a json text, it shows as arrays even
>>>>>> when there are single cartridge.
>>>>>>
>>>>>> The issue happens when the object is sent in response as below
>>>>>>
>>>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>>>
>>>>>>
>>>>>> In the code carridges is set as a list.
>>>>>>
>>>>>>
>>>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.
>>>>>>    asList(cartridges));
>>>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>>>
>>>>>>
>>>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>>>> I tried doing it too. But same result.
>>>>>>
>>>>>> What is the reason for this?
>>>>>>
>>>>>>
>>>>>> output [1]
>>>>>>
>>>>>> {
>>>>>>     "serviceGroup": [
>>>>>>         {
>>>>>>            * "cartridges": "tomcat",*
>>>>>>             "dependencies": {
>>>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>>>             },
>>>>>>             "name": "group5",
>>>>>>             "subGroups": "group1"
>>>>>>         }
>>>>>>     ]
>>>>>> }
>>>>>>
>>>>>> output [2]
>>>>>>
>>>>>> {
>>>>>>     "serviceGroup": {
>>>>>>         "cartridges": *[*
>>>>>> *            "tomcat",*
>>>>>> *            "php"*
>>>>>> *        ],*
>>>>>>         "dependencies": {
>>>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>>>             "terminationBehaviour": "terminate-dependents"
>>>>>>         },
>>>>>>         "name": "group6",
>>>>>>         "subGroups": "group2"
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>> [1]
>>>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>>>> --
>>>>>>
>>>>>> Udara Liyanage
>>>>>> Software Engineer
>>>>>> WSO2, Inc.: http://wso2.com
>>>>>> lean. enterprise. middleware
>>>>>>
>>>>>> web: http://udaraliyanage.wordpress.com
>>>>>> phone: +94 71 443 6897
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Udara Liyanage
>>>>> Software Engineer
>>>>> WSO2, Inc.: http://wso2.com
>>>>> lean. enterprise. middleware
>>>>>
>>>>> web: http://udaraliyanage.wordpress.com
>>>>> phone: +94 71 443 6897
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Udara Liyanage
>>>> Software Engineer
>>>> WSO2, Inc.: http://wso2.com
>>>> lean. enterprise. middleware
>>>>
>>>> web: http://udaraliyanage.wordpress.com
>>>> phone: +94 71 443 6897
>>>>
>>>
>>>
>>>
>>> --
>>> Best Regards,
>>> Nirmal
>>>
>>> Nirmal Fernando.
>>> PPMC Member & Committer of Apache Stratos,
>>> Senior Software Engineer, WSO2 Inc.
>>>
>>> Blog: http://nirmalfdo.blogspot.com/
>>>
>>
>>
>>
>> --
>>
>> Udara Liyanage
>> Software Engineer
>> WSO2, Inc.: http://wso2.com
>> lean. enterprise. middleware
>>
>> web: http://udaraliyanage.wordpress.com
>> phone: +94 71 443 6897
>>
>
>
>
> --
> Regards,
> Manula Chathurika Thantriwatte
> Software Engineer
> WSO2 Inc. : http://wso2.com
> lean . enterprise . middleware
>
> email : manulac@wso2.com / manula@apache.org
> phone : +94 772492511
> blog : http://manulachathurika.blogspot.com/
>
>
>
>


-- 
Regards,
Manula Chathurika Thantriwatte
Software Engineer
WSO2 Inc. : http://wso2.com
lean . enterprise . middleware

email : manulac@wso2.com / manula@apache.org
phone : +94 772492511
blog : http://manulachathurika.blogspot.com/

Re: Json response shows arrays as string when there are single value

Posted by Manula Chathurika Thantriwatte <ma...@wso2.com>.
Hi Udara,

I think the POJO conversion didn't happen correctly. That's why it didn't
deserialize correctly.

On Wed, Nov 5, 2014 at 7:41 PM, Udara Liyanage <ud...@wso2.com> wrote:

> Hi,
>
> You can find it [1]. Please note that other bean classes have public
> variables which are set when converting to a pojo. This bean as private
> variables and public getters and setters.
>
> [1]
> https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java
>
> On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <ni...@gmail.com>
> wrote:
>
>> Can you point to the relevant rest endpoint bean ?
>>
>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>
>>> Hi Nirmal,
>>>
>>> But it works in get deployment policy endpoint, so it can not be a
>>> limitation ?
>>>
>>> curl -X GET -H "Content-Type: application/json" -d @'app-php-only.json'
>>> -k   -u admin:admin
>>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>>> | python -m json.tool
>>>   % Total    % Received % Xferd  Average Speed   Time    Time     Time
>>>  Current
>>>                                  Dload  Upload   Total   Spent    Left
>>>  Speed
>>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:-- --:--:--
>>>  8538
>>> {
>>>     "deploymentPolicy": {
>>>         "id": "economyDeploymentPolicy",
>>>         "partitionGroup": [
>>>             {
>>>                 "id": "ec2",
>>>                 *"partition": [*
>>> *                    {*
>>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>>> *                        "isPublic": false,*
>>> *                        "partitionMax": 3,*
>>> *                        "partitionMin": 1,*
>>> *                        "property": [*
>>> *                            {*
>>> *                                "name": "region",*
>>> *                                "value": "ap-southeast-1"*
>>> *                            },*
>>> *                            {*
>>> *                                "name": "zone",*
>>> *                                "value": "ap-southeast-1a"*
>>> *                            }*
>>> *                        ],*
>>> *                        "provider": "ec2"*
>>> *                    }*
>>> *                ],*
>>>                 "partitionAlgo": "one-after-another"
>>>             }
>>>         ],
>>>         "public": false
>>>     }
>>> }
>>>
>>>
>>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>>> now cartridges are shown as arrays.
>>>> <value>cartridges</value>
>>>>
>>>> But we can't specify it for each variable.
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> When I execute the GET serviceGroup Stratos endpoint I get the
>>>>> folowing output in two different groups. Please note cartridges text  in
>>>>> bold. When there are only one cartridge, it shows as a String (output1),
>>>>> when there are multiple cartridges it is shown as an array (output2).
>>>>>
>>>>> But when I convert the object to a json text, it shows as arrays even
>>>>> when there are single cartridge.
>>>>>
>>>>> The issue happens when the object is sent in response as below
>>>>>
>>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>>
>>>>>
>>>>> In the code carridges is set as a list.
>>>>>
>>>>>
>>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.asList
>>>>>    (cartridges));
>>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>>
>>>>>
>>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>>> I tried doing it too. But same result.
>>>>>
>>>>> What is the reason for this?
>>>>>
>>>>>
>>>>> output [1]
>>>>>
>>>>> {
>>>>>     "serviceGroup": [
>>>>>         {
>>>>>            * "cartridges": "tomcat",*
>>>>>             "dependencies": {
>>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>>             },
>>>>>             "name": "group5",
>>>>>             "subGroups": "group1"
>>>>>         }
>>>>>     ]
>>>>> }
>>>>>
>>>>> output [2]
>>>>>
>>>>> {
>>>>>     "serviceGroup": {
>>>>>         "cartridges": *[*
>>>>> *            "tomcat",*
>>>>> *            "php"*
>>>>> *        ],*
>>>>>         "dependencies": {
>>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>>             "terminationBehaviour": "terminate-dependents"
>>>>>         },
>>>>>         "name": "group6",
>>>>>         "subGroups": "group2"
>>>>>     }
>>>>> }
>>>>>
>>>>> [1]
>>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>>> --
>>>>>
>>>>> Udara Liyanage
>>>>> Software Engineer
>>>>> WSO2, Inc.: http://wso2.com
>>>>> lean. enterprise. middleware
>>>>>
>>>>> web: http://udaraliyanage.wordpress.com
>>>>> phone: +94 71 443 6897
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Udara Liyanage
>>>> Software Engineer
>>>> WSO2, Inc.: http://wso2.com
>>>> lean. enterprise. middleware
>>>>
>>>> web: http://udaraliyanage.wordpress.com
>>>> phone: +94 71 443 6897
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Udara Liyanage
>>> Software Engineer
>>> WSO2, Inc.: http://wso2.com
>>> lean. enterprise. middleware
>>>
>>> web: http://udaraliyanage.wordpress.com
>>> phone: +94 71 443 6897
>>>
>>
>>
>>
>> --
>> Best Regards,
>> Nirmal
>>
>> Nirmal Fernando.
>> PPMC Member & Committer of Apache Stratos,
>> Senior Software Engineer, WSO2 Inc.
>>
>> Blog: http://nirmalfdo.blogspot.com/
>>
>
>
>
> --
>
> Udara Liyanage
> Software Engineer
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
>
> web: http://udaraliyanage.wordpress.com
> phone: +94 71 443 6897
>



-- 
Regards,
Manula Chathurika Thantriwatte
Software Engineer
WSO2 Inc. : http://wso2.com
lean . enterprise . middleware

email : manulac@wso2.com / manula@apache.org
phone : +94 772492511
blog : http://manulachathurika.blogspot.com/

Re: Json response shows arrays as string when there are single value

Posted by Udara Liyanage <ud...@wso2.com>.
Hi,

You can find it [1]. Please note that other bean classes have public
variables which are set when converting to a pojo. This bean as private
variables and public getters and setters.

[1]
https://github.com/apache/stratos/blob/docker-grouping-merge/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/definitions/ServiceGroupDefinition.java

On Wed, Nov 5, 2014 at 7:34 PM, Nirmal Fernando <ni...@gmail.com>
wrote:

> Can you point to the relevant rest endpoint bean ?
>
> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com> wrote:
>
>> Hi Nirmal,
>>
>> But it works in get deployment policy endpoint, so it can not be a
>> limitation ?
>>
>> curl -X GET -H "Content-Type: application/json" -d @'app-php-only.json'
>> -k   -u admin:admin
>> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
>> | python -m json.tool
>>   % Total    % Received % Xferd  Average Speed   Time    Time     Time
>>  Current
>>                                  Dload  Upload   Total   Spent    Left
>>  Speed
>> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:-- --:--:--
>>  8538
>> {
>>     "deploymentPolicy": {
>>         "id": "economyDeploymentPolicy",
>>         "partitionGroup": [
>>             {
>>                 "id": "ec2",
>>                 *"partition": [*
>> *                    {*
>> *                        "id": "AWSEC2AsiaPacificPartition1",*
>> *                        "isPublic": false,*
>> *                        "partitionMax": 3,*
>> *                        "partitionMin": 1,*
>> *                        "property": [*
>> *                            {*
>> *                                "name": "region",*
>> *                                "value": "ap-southeast-1"*
>> *                            },*
>> *                            {*
>> *                                "name": "zone",*
>> *                                "value": "ap-southeast-1a"*
>> *                            }*
>> *                        ],*
>> *                        "provider": "ec2"*
>> *                    }*
>> *                ],*
>>                 "partitionAlgo": "one-after-another"
>>             }
>>         ],
>>         "public": false
>>     }
>> }
>>
>>
>> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>
>>> Hi,
>>>
>>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>>> now cartridges are shown as arrays.
>>> <value>cartridges</value>
>>>
>>> But we can't specify it for each variable.
>>>
>>>
>>>
>>>
>>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> When I execute the GET serviceGroup Stratos endpoint I get the folowing
>>>> output in two different groups. Please note cartridges text  in bold. When
>>>> there are only one cartridge, it shows as a String (output1), when there
>>>> are multiple cartridges it is shown as an array (output2).
>>>>
>>>> But when I convert the object to a json text, it shows as arrays even
>>>> when there are single cartridge.
>>>>
>>>> The issue happens when the object is sent in response as below
>>>>
>>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>>
>>>>
>>>> In the code carridges is set as a list.
>>>>
>>>>
>>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.asList(
>>>>    cartridges));
>>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>>
>>>>
>>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml,
>>>> I tried doing it too. But same result.
>>>>
>>>> What is the reason for this?
>>>>
>>>>
>>>> output [1]
>>>>
>>>> {
>>>>     "serviceGroup": [
>>>>         {
>>>>            * "cartridges": "tomcat",*
>>>>             "dependencies": {
>>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>>                 "terminationBehaviour": "terminate-dependents"
>>>>             },
>>>>             "name": "group5",
>>>>             "subGroups": "group1"
>>>>         }
>>>>     ]
>>>> }
>>>>
>>>> output [2]
>>>>
>>>> {
>>>>     "serviceGroup": {
>>>>         "cartridges": *[*
>>>> *            "tomcat",*
>>>> *            "php"*
>>>> *        ],*
>>>>         "dependencies": {
>>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>>             "terminationBehaviour": "terminate-dependents"
>>>>         },
>>>>         "name": "group6",
>>>>         "subGroups": "group2"
>>>>     }
>>>> }
>>>>
>>>> [1]
>>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>>> --
>>>>
>>>> Udara Liyanage
>>>> Software Engineer
>>>> WSO2, Inc.: http://wso2.com
>>>> lean. enterprise. middleware
>>>>
>>>> web: http://udaraliyanage.wordpress.com
>>>> phone: +94 71 443 6897
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Udara Liyanage
>>> Software Engineer
>>> WSO2, Inc.: http://wso2.com
>>> lean. enterprise. middleware
>>>
>>> web: http://udaraliyanage.wordpress.com
>>> phone: +94 71 443 6897
>>>
>>
>>
>>
>> --
>>
>> Udara Liyanage
>> Software Engineer
>> WSO2, Inc.: http://wso2.com
>> lean. enterprise. middleware
>>
>> web: http://udaraliyanage.wordpress.com
>> phone: +94 71 443 6897
>>
>
>
>
> --
> Best Regards,
> Nirmal
>
> Nirmal Fernando.
> PPMC Member & Committer of Apache Stratos,
> Senior Software Engineer, WSO2 Inc.
>
> Blog: http://nirmalfdo.blogspot.com/
>



-- 

Udara Liyanage
Software Engineer
WSO2, Inc.: http://wso2.com
lean. enterprise. middleware

web: http://udaraliyanage.wordpress.com
phone: +94 71 443 6897

Re: Json response shows arrays as string when there are single value

Posted by Nirmal Fernando <ni...@gmail.com>.
Can you point to the relevant rest endpoint bean ?

On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <ud...@wso2.com> wrote:

> Hi Nirmal,
>
> But it works in get deployment policy endpoint, so it can not be a
> limitation ?
>
> curl -X GET -H "Content-Type: application/json" -d @'app-php-only.json' -k
>   -u admin:admin
> https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
> | python -m json.tool
>   % Total    % Received % Xferd  Average Speed   Time    Time     Time
>  Current
>                                  Dload  Upload   Total   Spent    Left
>  Speed
> 100   908    0   353  100   555   5364   8434 --:--:-- --:--:-- --:--:--
>  8538
> {
>     "deploymentPolicy": {
>         "id": "economyDeploymentPolicy",
>         "partitionGroup": [
>             {
>                 "id": "ec2",
>                 *"partition": [*
> *                    {*
> *                        "id": "AWSEC2AsiaPacificPartition1",*
> *                        "isPublic": false,*
> *                        "partitionMax": 3,*
> *                        "partitionMin": 1,*
> *                        "property": [*
> *                            {*
> *                                "name": "region",*
> *                                "value": "ap-southeast-1"*
> *                            },*
> *                            {*
> *                                "name": "zone",*
> *                                "value": "ap-southeast-1a"*
> *                            }*
> *                        ],*
> *                        "provider": "ec2"*
> *                    }*
> *                ],*
>                 "partitionAlgo": "one-after-another"
>             }
>         ],
>         "public": false
>     }
> }
>
>
> On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com> wrote:
>
>> Hi,
>>
>> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
>> now cartridges are shown as arrays.
>> <value>cartridges</value>
>>
>> But we can't specify it for each variable.
>>
>>
>>
>>
>> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com> wrote:
>>
>>> Hi,
>>>
>>> When I execute the GET serviceGroup Stratos endpoint I get the folowing
>>> output in two different groups. Please note cartridges text  in bold. When
>>> there are only one cartridge, it shows as a String (output1), when there
>>> are multiple cartridges it is shown as an array (output2).
>>>
>>> But when I convert the object to a json text, it shows as arrays even
>>> when there are single cartridge.
>>>
>>> The issue happens when the object is sent in response as below
>>>
>>> return Response.ok().entity(serviceGroupDefinition).build();
>>>
>>>
>>> In the code carridges is set as a list.
>>>
>>>
>>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.asList(
>>>    cartridges));
>>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>>
>>>
>>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml, I
>>> tried doing it too. But same result.
>>>
>>> What is the reason for this?
>>>
>>>
>>> output [1]
>>>
>>> {
>>>     "serviceGroup": [
>>>         {
>>>            * "cartridges": "tomcat",*
>>>             "dependencies": {
>>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>>                 "terminationBehaviour": "terminate-dependents"
>>>             },
>>>             "name": "group5",
>>>             "subGroups": "group1"
>>>         }
>>>     ]
>>> }
>>>
>>> output [2]
>>>
>>> {
>>>     "serviceGroup": {
>>>         "cartridges": *[*
>>> *            "tomcat",*
>>> *            "php"*
>>> *        ],*
>>>         "dependencies": {
>>>             "startupOrders": "group.group1,cartridge.tomcat",
>>>             "terminationBehaviour": "terminate-dependents"
>>>         },
>>>         "name": "group6",
>>>         "subGroups": "group2"
>>>     }
>>> }
>>>
>>> [1]
>>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>>> --
>>>
>>> Udara Liyanage
>>> Software Engineer
>>> WSO2, Inc.: http://wso2.com
>>> lean. enterprise. middleware
>>>
>>> web: http://udaraliyanage.wordpress.com
>>> phone: +94 71 443 6897
>>>
>>
>>
>>
>> --
>>
>> Udara Liyanage
>> Software Engineer
>> WSO2, Inc.: http://wso2.com
>> lean. enterprise. middleware
>>
>> web: http://udaraliyanage.wordpress.com
>> phone: +94 71 443 6897
>>
>
>
>
> --
>
> Udara Liyanage
> Software Engineer
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
>
> web: http://udaraliyanage.wordpress.com
> phone: +94 71 443 6897
>



-- 
Best Regards,
Nirmal

Nirmal Fernando.
PPMC Member & Committer of Apache Stratos,
Senior Software Engineer, WSO2 Inc.

Blog: http://nirmalfdo.blogspot.com/

Re: Json response shows arrays as string when there are single value

Posted by Udara Liyanage <ud...@wso2.com>.
Hi Nirmal,

But it works in get deployment policy endpoint, so it can not be a
limitation ?

curl -X GET -H "Content-Type: application/json" -d @'app-php-only.json' -k
  -u admin:admin
https://localhost:9443/stratos/admin/policy/deployment/economyDeploymentPolicy
| python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time
 Current
                                 Dload  Upload   Total   Spent    Left
 Speed
100   908    0   353  100   555   5364   8434 --:--:-- --:--:-- --:--:--
 8538
{
    "deploymentPolicy": {
        "id": "economyDeploymentPolicy",
        "partitionGroup": [
            {
                "id": "ec2",
                *"partition": [*
*                    {*
*                        "id": "AWSEC2AsiaPacificPartition1",*
*                        "isPublic": false,*
*                        "partitionMax": 3,*
*                        "partitionMin": 1,*
*                        "property": [*
*                            {*
*                                "name": "region",*
*                                "value": "ap-southeast-1"*
*                            },*
*                            {*
*                                "name": "zone",*
*                                "value": "ap-southeast-1a"*
*                            }*
*                        ],*
*                        "provider": "ec2"*
*                    }*
*                ],*
                "partitionAlgo": "one-after-another"
            }
        ],
        "public": false
    }
}


On Wed, Nov 5, 2014 at 7:21 PM, Udara Liyanage <ud...@wso2.com> wrote:

> Hi,
>
> When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
> now cartridges are shown as arrays.
> <value>cartridges</value>
>
> But we can't specify it for each variable.
>
>
>
>
> On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com> wrote:
>
>> Hi,
>>
>> When I execute the GET serviceGroup Stratos endpoint I get the folowing
>> output in two different groups. Please note cartridges text  in bold. When
>> there are only one cartridge, it shows as a String (output1), when there
>> are multiple cartridges it is shown as an array (output2).
>>
>> But when I convert the object to a json text, it shows as arrays even
>> when there are single cartridge.
>>
>> The issue happens when the object is sent in response as below
>>
>> return Response.ok().entity(serviceGroupDefinition).build();
>>
>>
>> In the code carridges is set as a list.
>>
>>
>>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.asList(
>>    cartridges));
>>    2. servicegroupDef.setCartridges(cartridgesDef);
>>
>>
>> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml, I
>> tried doing it too. But same result.
>>
>> What is the reason for this?
>>
>>
>> output [1]
>>
>> {
>>     "serviceGroup": [
>>         {
>>            * "cartridges": "tomcat",*
>>             "dependencies": {
>>                 "startupOrders": "group.group1,cartridge.tomcat",
>>                 "terminationBehaviour": "terminate-dependents"
>>             },
>>             "name": "group5",
>>             "subGroups": "group1"
>>         }
>>     ]
>> }
>>
>> output [2]
>>
>> {
>>     "serviceGroup": {
>>         "cartridges": *[*
>> *            "tomcat",*
>> *            "php"*
>> *        ],*
>>         "dependencies": {
>>             "startupOrders": "group.group1,cartridge.tomcat",
>>             "terminationBehaviour": "terminate-dependents"
>>         },
>>         "name": "group6",
>>         "subGroups": "group2"
>>     }
>> }
>>
>> [1]
>> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
>> --
>>
>> Udara Liyanage
>> Software Engineer
>> WSO2, Inc.: http://wso2.com
>> lean. enterprise. middleware
>>
>> web: http://udaraliyanage.wordpress.com
>> phone: +94 71 443 6897
>>
>
>
>
> --
>
> Udara Liyanage
> Software Engineer
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
>
> web: http://udaraliyanage.wordpress.com
> phone: +94 71 443 6897
>



-- 

Udara Liyanage
Software Engineer
WSO2, Inc.: http://wso2.com
lean. enterprise. middleware

web: http://udaraliyanage.wordpress.com
phone: +94 71 443 6897

Re: Json response shows arrays as string when there are single value

Posted by Udara Liyanage <ud...@wso2.com>.
Hi,

When I add the name of the variable to the cxf-servlet.xml as serializeAsArray,
now cartridges are shown as arrays.
<value>cartridges</value>

But we can't specify it for each variable.




On Wed, Nov 5, 2014 at 6:35 PM, Udara Liyanage <ud...@wso2.com> wrote:

> Hi,
>
> When I execute the GET serviceGroup Stratos endpoint I get the folowing
> output in two different groups. Please note cartridges text  in bold. When
> there are only one cartridge, it shows as a String (output1), when there
> are multiple cartridges it is shown as an array (output2).
>
> But when I convert the object to a json text, it shows as arrays even when
> there are single cartridge.
>
> The issue happens when the object is sent in response as below
>
> return Response.ok().entity(serviceGroupDefinition).build();
>
>
> In the code carridges is set as a list.
>
>
>    1. List<String> cartridgesDef = new ArrayList<String>(Arrays.asList(
>    cartridges));
>    2. servicegroupDef.setCartridges(cartridgesDef);
>
>
> [1] suggested to set serializeAsArray as true in cxf-servlet.xml.xml, I
> tried doing it too. But same result.
>
> What is the reason for this?
>
>
> output [1]
>
> {
>     "serviceGroup": [
>         {
>            * "cartridges": "tomcat",*
>             "dependencies": {
>                 "startupOrders": "group.group1,cartridge.tomcat",
>                 "terminationBehaviour": "terminate-dependents"
>             },
>             "name": "group5",
>             "subGroups": "group1"
>         }
>     ]
> }
>
> output [2]
>
> {
>     "serviceGroup": {
>         "cartridges": *[*
> *            "tomcat",*
> *            "php"*
> *        ],*
>         "dependencies": {
>             "startupOrders": "group.group1,cartridge.tomcat",
>             "terminationBehaviour": "terminate-dependents"
>         },
>         "name": "group6",
>         "subGroups": "group2"
>     }
> }
>
> [1]
> http://stackoverflow.com/questions/18918091/when-a-list-has-only-one-element-cxf-return-the-object-instead-a-js-array
> --
>
> Udara Liyanage
> Software Engineer
> WSO2, Inc.: http://wso2.com
> lean. enterprise. middleware
>
> web: http://udaraliyanage.wordpress.com
> phone: +94 71 443 6897
>



-- 

Udara Liyanage
Software Engineer
WSO2, Inc.: http://wso2.com
lean. enterprise. middleware

web: http://udaraliyanage.wordpress.com
phone: +94 71 443 6897