From 1b744dbd580cc353d18b119eef361abe1850a91b Mon Sep 17 00:00:00 2001 From: "Eduardo Ramos Testillano (ert)" Date: Mon, 1 Nov 2021 13:56:53 +0100 Subject: [PATCH] Fix xml to json converter When an array has a unique element, xmltodict does not parse it as an array, but a single object. This causes a problem in the diameter xml conversion because the library for reverse conversion [0] won't follow the diameter message dtd template. Fortunately, xmltodict supports [1] force array for specific node name, so we will force this for 'avp' which is the one affected. [0] https://github.com/testillano/json2xml [1] https://stackoverflow.com/questions/37207353/xmltodict-does-not-return-a-list-for-one-element --- .../resources/rest_api/helpers/diameterJsonHelper/xml2json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/diameter/launcher/resources/rest_api/helpers/diameterJsonHelper/xml2json.py b/example/diameter/launcher/resources/rest_api/helpers/diameterJsonHelper/xml2json.py index 707053d..bb25d8e 100755 --- a/example/diameter/launcher/resources/rest_api/helpers/diameterJsonHelper/xml2json.py +++ b/example/diameter/launcher/resources/rest_api/helpers/diameterJsonHelper/xml2json.py @@ -46,7 +46,7 @@ except: # force the value just in case xmltodict implementation # changes. The anna::core::functions::json2xml helper, # assumes this prefix in order to work properly. -result=xmltodict.parse(xml, attr_prefix='@') +result=xmltodict.parse(xml, force_list={'avp'}, attr_prefix='@') if parent: result = { parent: result } -- 2.20.1