2023 Sep 22 8:03 AM
hi all,
I am calling
r_json = NEW /ui2/cl_json( pretty_name = /ui2/cl_json=>pretty_mode-camel_case
compress = abap_true )->serialize_int( data = is_grid_data ).
where compress flag is true due to which if there is any field value with intial it is not getting added in json.
but is there any option where we can tell the method though that is initial it must get added in json.
Here is a example
types: begin of ty_test,
abc type c,
tab1 type string-table,
val2 type string,
col3 type n,
end of ty_test.
here though tab1 is inital i want that to be added in json
is there any opion i can tell that tab1 should be there in json though it is inital.
2023 Sep 24 4:20 PM
Hi Kiran,
if you want to have a custom logic for compressing only some fields you need to extend the class and overwrite the IS_COMPRESSIBLE method.
More info and example can be found here: abap-to-json/docs/class-extension.md at main · SAP/abap-to-json (github.com)
BR, Alex.
2023 Sep 22 8:12 AM
One ugly way to do this is that you put some special unique constant value inside that variable.
Lets say:
CONSTANTS: lc_dummy_value TYPE string VALUE '[DUMMY_DELETE_ABAP_VALUE]'.
And than later find it in result JSON string and delete it.
In your case it would be little bit more complicated because you have not a simple field but array (itab). So you will probably need to delete also some JSON brackets around the constant to make tab1 initial in JSON...
2023 Sep 22 9:34 AM
Any Better solution is appreciated.
Actually we have 2 complex structures which involves lot of tables structures and strings integers.
2023 Sep 22 12:04 PM
kiran.rachamalla Other solution could be creation of multiple JSONs (one without compress, one with compress etc.) and then combine them together. But that is also not ideal.
Another way is you can explore JSON creation using TRANSFORMATION. But I do not have much experience with it. So I am not sure if it will work for you. You can find blogs and resources online.
For example here is nice blog with links to other sources:
https://blogs.sap.com/2022/10/27/abap-fast-json-serialization/
2023 Nov 17 12:50 AM
The Problem is Even the fields with boolean flags are also not getting when compressed flag is set true due to which false flag is not going to UI. there are lot of boolean flags in my json.
Regards,
kiran rachamalla.
2023 Sep 23 10:06 AM
Problem with formatting of your question. This is better:
r_json = NEW /ui2/cl_json( pretty_name = /ui2/cl_json=>pretty_mode-camel_case
compress = abap_true
)->serialize_int( data = is_grid_data ).
where compress flag is true due to which if there is any field value with intial it is not getting added in json.
but is there any option where we can tell the method though that is initial it must get added in json.
Here is a example
types: begin of ty_test,
abc type c,
tab1 type string-table,
val2 type string,
col3 type n,
end of ty_test.
here though tab1 is inital i want that to be added in json
is there any opion i can tell that tab1 should be there in json though it is inital.
2023 Sep 23 1:11 PM
Out of curiosity, why is it needed to generate these few properties with an initial value? Also, are these string, number, boolean, null, object or array properties?
2023 Sep 24 4:20 PM
Hi Kiran,
if you want to have a custom logic for compressing only some fields you need to extend the class and overwrite the IS_COMPRESSIBLE method.
More info and example can be found here: abap-to-json/docs/class-extension.md at main · SAP/abap-to-json (github.com)
BR, Alex.
2023 Nov 17 1:03 AM