Skip to content

Commit 2f38de7

Browse files
Update basic.md
1 parent 19deaf0 commit 2f38de7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/basic.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,39 @@ Output JSON
234234
```
235235
For deserialization, the flag tells the deserializer that the value shall be placed in a non-key field of the structure.
236236

237+
238+
Here is an example of deserialization, in which mentioned above two options can be used:
239+
```json
240+
{
241+
"id": "509e28db-6794-4e02-91d3-e35f4c7310e9",
242+
"form": {
243+
"Authorised": "TBB ENTERPRISE SDN. BHD.",
244+
"Fax No:": "92225491",
245+
"Issued Date :": "02-10-2024",
246+
"Voluntary Excess": "0.00",
247+
"Page": "2",
248+
"Allianz General Insurance Company (Malaysia) Berhad": "(200601015674)",
249+
}
250+
}
251+
```
252+
Look into sub-attributes of the "form" field. They can not be easily mapped into any ABAP structure, because attribute names contain spaces, special characters, etc. The best way would be to deserialize this fragment in a table with a key, corresponding to the attribute name. The example code for deserialization then will look like this:
253+
```abap
254+
TYPES: BEGIN OF ts_name_value,
255+
name TYPE string,
256+
value TYPE string,
257+
END OF ts_name_value,
258+
BEGIN OF ts_data,
259+
id TYPE string,
260+
form TYPE SORTED TABLE OF ts_name_value WITH UNIQUE KEY name,
261+
END OF ts_data.
262+
263+
DATA: ls_data TYPE ts_data.
264+
/ui2/cl_json=>deserialize( EXPORTING json = lv_json
265+
assoc_array = abap_true
266+
assoc_array_opt = abap_true
267+
CHANGING data = ls_data ).
268+
```
269+
237270
# Supported SAP_BASIS releases
238271
The code was tested from SAP_BASIS 7.00 and higher, but I do not see the reasons why it cannot be downported on lower releases either. But if you plan to use it on SAP_BASIS 7.02 and higher (and do not need property name pretty-printing) better consider the standard solution for **ABAP**, using [CALL TRANSFORMATION](advanced.md#json-to-abap-transformation-with-the-use-of-call-transformation). It shall be faster, while implemented in the kernel. Maybe the best will be, if you need support in lower SAP_BASIS releases as well as in 7.02 and higher, to modify the provided class in a way to generate the same **JSON** format as standard ABAP CALL TRANSFORMATION for JSON does and redirect flow to home-made code or built-in **ABAP** transformation depending on SAP_BASIS release.
239272

0 commit comments

Comments
 (0)