JSON serializer entry

If I want to develop a serializer for a language for which it does not exist (for example, ABAP), what might be its efforts? Does this just include writing the "text equivalent" of an ABAP serial block - how would I solve complex objects. What would be the best starting point for this?

+1
source share
3 answers

Update: Starting with releases 7.02 and 7.03 / 7.31 (kernel patch 116), JSON is supported natively in ABAP - check out this blog post by Horst Keller.

You must first search for ABAP and JSON using the site: sap.com, and then select one of the existing projects to learn and contribute. However, if you are still not using the NIH bonus points, make sure you know how to use common types, field characters, RTTI and recursion inside out, and then recursively transition to a complex data structure using RTTI. Once you have done this, it is easy to assemble any output string.

+2
source

There is a class that does just that: CL_TREX_JSON_SERIALIZER. The only thing it does not have (and SAP told me through a client message that they will not fix it, they do not support this code) puts the attribute in double quotes.

This is easy to install by adding line 52 to CL_TREX_JSON_SERIALIZER-RECURSE:

CONCATENATE '"' <abapcomp>-name '"' c_colon INTO l_value . 

Program Example:

 "We are going to serialize an error DATA: wa_error TYPE bapireturn. "Reference to the serializer DATA: cl_serializer TYPE REF TO zcl_trex_json_serializer. "Final output DATA: l_json_string TYPE string. wa_error-type = 'E'. wa_error-code = 'BC' . wa_error-message = 'This will serialize correctly.'. CREATE OBJECT cl_serializer EXPORTING DATA = wa_error. cl_serializer->serialize( ) . l_json_string = cl_serializer->get_data( ) . WRITE l_json_string. 

I am using zcl_trex_json_serializer which is a cl_trex_json_serializer clone with the above fix. This code will return:

{"type": "E", "code": "BC", "message": "This will serialize correctly.", "log_no": "," log_msg_no ":" 000000 "," message_v1 ":", " message_v2 ":", "message_v3": "," message_v4 ":" "}

I used this code for structures containing tables, etc .; the code seems to be able to handle all of this.

+1
source

In addition to checking vwegert response Convert SAP to Json

0
source

All Articles