On Wed, Nov 5, 2014 at 3:31 PM, Udara Liyanage <[email protected]> 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 <[email protected]>
> 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 <[email protected]> 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 <[email protected]>
>>> wrote:
>>>
>>>> Can you point to the relevant rest endpoint bean ?
>>>>
>>>> On Wed, Nov 5, 2014 at 2:52 PM, Udara Liyanage <[email protected]> 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 <[email protected]> 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 <[email protected]>
>>>>>> 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/