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
XML2JSON Converter when there are two xml nodes with same name but one is array #5
Comments
Hi Pedro, using XPath to determine the node that needs to be forced as an array is indeed a more flexible approach. However, based on your particular example on customFields, I don’t think you need it. The first occurrence only happens once, while the second occurrence happens twice. Have you tried the conversion without setting arrayFieldList value? That is only useful if you want to explicitly force it to be an array. Otherwise it automatically determines if it should be an array or not based on the occurrence in the payload. |
Hi Swee, thanks for your reply. Actually I do have the situation below as well, where wouldn't work based on the occurrence: XML:
Desired JSON:
|
Hi Pedro I have released a new version 2.2.0 whereby the JSON processing has been switched to using Groovy's built-in JSON capability. Alongside that, I have added new parameter arrayGPathList to cater for your scenario. The parameter works based on GPath of the target JSON structure, instead of XPath of the source XML structure. For your case, you can configure it like: arrayGPathList = test.customer.customFields Give it a try and let me know how it goes. |
Hi, Working perfectly, thank you. Many many thanks. Pedro Baroni |
Great to hear that it is working now. The reference blog has also been updated. I'll close this issue. |
Hi Eng Swee Yeoh. I've got an use case where a XML to be converted to JSON has two XML nodes with same name, one should be array and the other not. Given that I am not able to use arrayFieldList as it would change the two nodes to array in JSON. So I would like to suggest using XPATH instead of NomeName in the arrayFieldList parameter, so it would be possible to define only one Node to be JSON array and other not. Example below regarding of "customFields":
XML:
Desired JSON:
Kind Regards.
Pedro Baroni
The text was updated successfully, but these errors were encountered: