cancel
Showing results for 
Search instead for 
Did you mean: 

XML to JSON conversion issue @ REST receiver adapter

07-11-2022 2:57 PM
Bhargavakrishna Active Contributor
3155 views 6 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

Hallo All,

We are working on REST to REST synchronous scenario. The output (xml) from mapping looks fine, but when it is transformed to JSON through REST receiver channel.

We tried using the custom XML/JSON conversion for the field "Text" in the REST receiver adapter and it is not working as expected. please check the below for more details about the requirement.

output after mapping

<?xml version="1.0" encoding="UTF-8"?>

<ns0:UIT_MT_IT_REQUEST xmlns:ns0="urn:test/po/MT-it">

<root>

<query_table>BSEC</query_table>

<DELIMITER>~</DELIMITER>

<ROWCOUNT>5</ROWCOUNT>

<ROWSKIPS>0</ROWSKIPS>

<options>

<Text>'0300'</Text>

</options>

<options>

<Text>'2022%'</Text>

</options>

<options>

<Text>IN ('320000000',</Text>

<Text>'320000002',</Text>

<Text>'320000003',</Text>

<Text>'320000004')</Text>

</options>

<root>

Output from REST Receiver adapter

{
		"query_table": "BSEC",
		"DELIMITER": "~",
		"ROWCOUNT": 5,
		"ROWSKIPS": 0,
		"options": [
			{
				"Text": "'0300'"
			},
			{
				"Text": "'2022%'"
			},
			{
				"Text": [
					"IN ('320000000',",
					"'320000002',",
					"'320000003',",
					"'320000004')"
				]
			}
		],
}

Expected output

{
	"query_table": "BSEC",
	"DELIMITER": "~",
	"ROWCOUNT": 5,
	"ROWSKIPS": 0,
	"options": [
		{
			"Text": "'0300' "
		},
		{
			"Text": "'2022%' "
		},
		{
			"Text": "IN ('320000000',"
		},
		{
			"Text": "'320000002', "
		},
		{
			"Text": "'320000003', "
		},
		{
			"Text": "'320000004', "
		}
	]
}

Rest Receiver channel configuration

Appreciate your valuable inputs and suggestions to get the expected output from the REST receiver channel.

Thanks in advance.

Best Regards

Bhargava Krishna Talasila

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Bhargavakrishna
Active Contributor
0 Likes

Created target XSD and adjusted the mapping to generate multiple Header elements "options".

Please check the below output xml generated from mapping and the JSON structure generated by REST adapter.

<?xml version="1.0" encoding="UTF-8"?>
	<root>
		<query_table>BSEC</query_table>
		<DELIMITER>~</DELIMITER>
		<ROWCOUNT>5</ROWCOUNT>
		<ROWSKIPS>0</ROWSKIPS>
		<options>
			<Text>'0300'</Text>
		</options>
		<options>
			<Text>'2022%'</Text>
		</options>
		<options>
			<Text>IN ('320000000',</Text>
		</options>
		<options>
			<Text>'320000002',</Text>
		</options>
		<options>
			<Text>'320000003',</Text>
		</options>
		<options>
			<Text>'320000004')</Text>
		</options>
	</root>

JSON output from REST adapter

{
			"query_table": "BSEC",
			"DELIMITER": "~",
			"ROWCOUNT": 5,
			"ROWSKIPS": 0,
			"options": [
				{
					"Text": "'0300'"
				},
				{
					"Text": "'2022%'"
				},
				{
					"Text": "IN ('320000000',"
				},
				{
					"Text": "'320000002',"
				},
				{
					"Text": "'320000003',"
				},
				{
					"Text": "'320000004')"
				}
			]
}

Regards

Bhargava Krishna

Answers (2)

Answers (2)

Ryan-Crosby
Active Contributor
0 Likes

Hi Bhargava,

You would need to map the <Text> elements into a single <options> tag. The converter is creating an array of options that each contain the individual text elements contained within the source tag (an array of elements in the case of the last tag). Create an XSLT or regular graphical message mapping to convert the XML to the following and then it should be fine:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:UIT_MT_IT_REQUEST xmlns:ns0="urn:test/po/MT-it">
<root>
<query_table>BSEC</query_table>
<DELIMITER>~</DELIMITER>
<ROWCOUNT>5</ROWCOUNT>
<ROWSKIPS>0</ROWSKIPS>
<options>
<Text>'0300'</Text>
<Text>'2022%'</Text>
<Text>IN ('320000000',</Text>
<Text>'320000002',</Text>
<Text>'320000003',</Text>
<Text>'320000004')</Text>
</options>
<root>

Regards,

Ryan Crosby

Bhargavakrishna
Active Contributor
0 Likes

Hi Ryan,

Thank you for your response and suggestion. The XML will be transformed to below JSON format. When posting this payload to the REST endpoint,it is giving the sysntax error.

{

"query_table": "BSEC",

"DELIMITER": "~",

"ROWCOUNT": 5,

"ROWSKIPS": 0,

"options": {

"Text": [

"'0300'",

"'2022%'",

"IN ('320000000',",

"'320000002',",

"'320000003',",

"'320000004')"

]

}

}

Regards

Bhargava Krishna

Ryan-Crosby
Active Contributor

bhargavakrishna.talasila - looks like you answered at the same time I was sending a suggestion and I didn't notice the subtlety of the options array, but looks like you solved it with a minor structure variation of wrapping each text into an options tag.

0 Likes

Hi!

Why not to just delete "root" element from target structure?

Regards, Evgeniy.

Bhargavakrishna
Active Contributor
0 Likes

Hi Evgeniy,

Sorry that was a typo error when copying the payload.

i'm deleting this using module paramter "setIgnoredElements" in the channel.

Regards

Bhargava Krishna Talasila