Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlDeserializer fails to deserialize a CriterionPolicyError #128

Closed
bhdouglass opened this issue Mar 23, 2016 · 4 comments
Closed

XmlDeserializer fails to deserialize a CriterionPolicyError #128

bhdouglass opened this issue Mar 23, 2016 · 4 comments
Assignees

Comments

@bhdouglass
Copy link

The XmlDeserializer fails to deserialize a CriterionPolicyError with the following exception: ReflectionException: Property _parameterMap does not exist. This is because the CriterionPolicyError is a child class to PolicyViolationError and the PolicyViolationError class does not have a _parameterMap property (but PolicyViolationError's parent class ApiError does). I've worked around the issue by hacking the XmlDeserializer to also check the parent class' parent when looking for a _parameterMap.

A simple example that triggers this error (using PHP v5.6 and AdWords API v201509):

$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<mutateResponse xmlns="https://adwords.google.com/api/adwords/cm/v201509">
    <rval>
        <errorList>
            <errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CriterionPolicyError">
                <fieldPath>operations[52].operand.criterion.text</fieldPath>
                <trigger>text</trigger>
                <errorString>CriterionPolicyError.POLICY_ERROR</errorString>
                <ApiError.Type>CriterionPolicyError</ApiError.Type>
                <key>
                    <policyName>pharma</policyName>
                    <violatingText>text</violatingText>
                </key>
                <externalPolicyName>Online pharmacy certification required</externalPolicyName>
                <externalPolicyUrl></externalPolicyUrl>
                <externalPolicyDescription>
                    Description
                </externalPolicyDescription>
                <isExemptable>true</isExemptable>
                <violatingParts>
                    <index>9</index>
                    <length>4</length>
                </violatingParts>
            </errors>
        </errorList>
        <index>52</index>
    </rval>
</mutateResponse>

XML;

$deserializer = new \XmlDeserializer(\BatchJobUtils::$CLASS_MAP);
$results = $deserializer->ConvertXmlToObject($xml);
print_r($results);

And the stack trace is:

#0 Google/Api/Ads/AdWords/Util/XmlDeserializer.php(126): ReflectionClass->getProperty('_parameterMap')
#1 Google/Api/Ads/AdWords/Util/XmlDeserializer.php(92): XmlDeserializer->ConvertElementToObject(Object(DOMElement), 'ApiError')
#2 Google/Api/Ads/AdWords/Util/XmlDeserializer.php(92): XmlDeserializer->ConvertElementToObject(Object(DOMElement), 'ErrorList')
#3 Google/Api/Ads/AdWords/Util/XmlDeserializer.php(92): XmlDeserializer->ConvertElementToObject(Object(DOMElement), 'MutateResult')
#4 Google/Api/Ads/AdWords/Util/XmlDeserializer.php(63): XmlDeserializer->ConvertElementToObject(Object(DOMElement))
#5 XmlDeserializer->ConvertXmlToObject('<?xml version="...')
@fiboknacky
Copy link
Member

Thanks for reporting this.
I'll look into this and update this thread when it's fixed.

Knack

@bhdouglass
Copy link
Author

Thank you!

@fiboknacky
Copy link
Member

This is fixed with v8.2.1

@bhdouglass
Copy link
Author

That works wonderfully, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants