-
-
Notifications
You must be signed in to change notification settings - Fork 585
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
XmlKeyValueStore annotation does not seem to deserialize properly #139
Comments
I think that |
@adrienbrault do you know where I can look so I might be able to contribute a fix? |
Hum, actually, try to use |
Otherwise, it will probably be in there https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/XmlDeserializationVisitor.php#L144-L197 |
I have tried your suggestion but it won't help .. |
Ouch, that piece of code is quite in the core of JMS Serializer. That will take some time to digest. |
This will likely be complicated/impossible as we have no type information for key value pairs in XML (or we need to embed the information into the document). Another, simpler solution would be to introduce a Parameters object in your code where you can keep the different settings. |
I am unable to predict which exact settings are necessary due to the way this is set up; is it possible and what is the easiest way to extract an array of variable keys?
I don't mind adding a parameters collection object by the way; those flexible keys are my main requirement |
@mvriel Hm, maybe try |
Right now, this is not easy in XML as we have no type information for each individual key (to which value should we convert the data, boolean, string, integer, etc.?). You could probably write a listener which extracts the parameters from XML and set them on your object if you know the types. A more long-term fix in the serializer would be to embed type information: <parameters>
<my-parameter type="string">123</my-parameter>
<my-random-parameter type="boolean">true</my-random-parameter>
</parameters> Although the caveat here is that you probably don't want the XML to come from input that can be manipulated by a possibly malicious user. |
Is the same complexity applicable when I know up front that all keys should be strings? |
That would make things easier indeed. It is not possible right now as the element name is hard-coded (see https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/XmlDeserializationVisitor.php#L146). Are you tied to this format, or would something like this work:
|
Thanks for all your input; I have decided to go for your last suggestion. I had hoped I would be able to use the former as that would have prevented a BC break but given the limited time I have available I have chosen for this one. Again, thank you! |
For phpDocumentor we use the JMS Serializer library to convert settings XML files into models. This worked perfectly until we tried to add a key-value store series of parameters to our objects.
The error seems to occur with the following XML (this is actually generated by the serialize method).
When I deserialize this XML (see https://github.com/phpDocumentor/phpDocumentor2/blob/develop/src/phpDocumentor/Transformer/Template/Collection.php#L96) with the template model (https://github.com/phpDocumentor/phpDocumentor2/blob/develop/src/phpDocumentor/Transformer/Template.php#L66) I notice that the $parameters property never receives any elements.
Am I doing something wrong or is this an issue with the XmlKeyValueStore annotation/functionality?
The text was updated successfully, but these errors were encountered: