Search code examples
javaphpstringsoapwsdl

Soap - List of one string is sended as string


I'm sending from Java backend via SOAP an ArrayList of Strings to PHP client.

WSDL:

<xs:element name="getSearchHintResponse">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="1" name="hint">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="1" minOccurs="1" name="text" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

It is working fine, when I'm sending more then one String, but when is only one String sended, then php side didn't recognize, that it is an Array of String and SOAP (or PHP?) somehow converts it to one String.

Php log of one String:

object(stdClass)#260 (1) {
    ["hint"]=>
    object(stdClass)#261 (1) {
        ["text"]=>
        string(5) "ales "
    }
}

Php log with more Strings:

object(stdClass)#260 (1) {
    ["hint"]=>
    array(2) {
        [0]=>
        object(stdClass)#261 (1) {
            ["text"]=>
            string(4) "ale  "
        }
        [1]=>
        object(stdClass)#262 (1) {
            ["text"]=>
            string(5) "ales "
        }
    }
}

Is there a possibility, how can I fix this on Java backend side (where WSDL is created) or do I need to force php dev to check it for String?

EDIT:

Java Endpoint:

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getSearchHintRequest")
@ResponsePayload
public GetSearchHintResponse getSearchHintRequest(@RequestPayload GetSearchHintRequest request) throws Exception {
        GetSearchHintResponse response = new GetSearchHintResponse();
        List<GetSearchHintResponse.Hint> hints = response.getHint();
        Collection<? extends String> hintsStr = searchComponent.getSearchHint(request.getBeginning(),
                request.getCollections(), request.getHintCount());
        for (String hintStr : hintsStr) {
            GetSearchHintResponse.Hint hint = new GetSearchHintResponse.Hint();
            hint.setText(hintStr + "\t");
            hints.add(hint);
        }
        return response;
}

Solution

  • As XtremeBaumer mentioned in comments:

    you could check for the length on your side and if its just 1 element, you add an empty string ("") to the array. i think that should solve it at first, but i am not sure about the impact on php dev – XtremeBaumer Jan 12 at 8:30

    It was little dirty way, with empty div, but it works.