stratos-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Manula Chathurika Thantriwatte <manu...@wso2.com>
Subject Re: Json response shows arrays as string when there are single value
Date Thu, 06 Nov 2014 10:59:40 GMT
Hi Udara,

Have you commit the changes.

On Wed, Nov 5, 2014 at 8:16 PM, Udara Liyanage <udara@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 <nirmal070125@gmail.com>
> wrote:
>
>>
>>
>> On Wed, Nov 5, 2014 at 3:31 PM, Udara Liyanage <udara@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 <udara@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 <udara@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 <udara@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 <udara@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/

Mime
View raw message