Skip to content

xsi:type subclass #573

@diegobanos

Description

@diegobanos
Q A
Version 4.1.1

Support Question

Hello!

This might be a dumb question, I am not super familiar with SOAP requests. I am testing around with this client and using the wizard to automatically set up my classmap and client.

I am facing the following problem with the decoding of responses. I am trying to decode into the specific class/subclass based on the xsi:type. However, my response is always defaulting to the parent class and it does not include all the properties returned by the response.

Here is a mockup of the problem:

Given a XML response as such:

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header/>
    <S:Body>
        <ns2:Response xmlns:ns2="<URI>">
            <return>
                <responses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:A">
                    <foo>foo</foo>
                </responses>
                <responses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:B">
                    <foo>foo</foo>
                    <bar>bar</bar>
                </responses>
            </return>
        </ns2:Response>
    </S:Body>
</S:Envelope>

And the following class structure:

class Response
{
    protected ?Return $return = null;
}

class Return
{
    /**
    * @var null|array<int<0,max>, A>
    */
    protected ?array $responses = null;
}

class A
{
    protected string $foo;
}

class B extends A
{
    protected string $bar;
}

I was expecting that after decoding, I'd get an object like this:

Response {
    -return: Return {
        -responses: array:2 [
            0 => A {
                -foo: "foo"
            }
            1 => B {
                -foo: "foo"
                -bar: "bar"
            }
        ]
    }
}

However, the responses are always mapped to the super class and I am losing the bar property:

Response {
    -return: Return {
        -responses: array:2 [
            0 => A {
                -foo: "foo"
            }
            1 => A {
                -foo: "foo"
            }
        ]
    }
}

I am not sure if this is a common problem that can be fixed with some configuration, or if this particular SOAP response using xsi:type requires me to write a custom Decoder.

I'd appreciate any type of guidance! Thanks for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions