Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json: serialize xstring #889

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"license": "MIT",
"dependencies": {
"@abaplint/cli": "^2.108.11",
"@abaplint/cli": "^2.110.1",
"@abaplint/database-sqlite": "^2.8.25",
"@abaplint/runtime": "^2.8.25",
"@abaplint/transpiler-cli": "^2.8.25",
Expand Down
2 changes: 2 additions & 0 deletions src/json/#ui2#cl_json.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ CLASS /ui2/cl_json IMPLEMENTATION.
ELSE.
r_json = '"' && escape( val = |{ data }| format = cl_abap_format=>e_json_string ) && '"'.
ENDIF.
WHEN cl_abap_typedescr=>typekind_xstring.
r_json = '"' && cl_http_utility=>encode_x_base64( data ) && '"'.
WHEN cl_abap_typedescr=>typekind_string.
r_json = '"' && escape( val = data format = cl_abap_format=>e_json_string ) && '"'.
WHEN cl_abap_typedescr=>typekind_int.
Expand Down
27 changes: 27 additions & 0 deletions src/json/#ui2#cl_json.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,37 @@ CLASS ltcl_serialize DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT F
METHODS time_field FOR TESTING RAISING cx_static_check.
METHODS numc_field FOR TESTING RAISING cx_static_check.
METHODS numc_field2 FOR TESTING RAISING cx_static_check.
METHODS serialize_empty_xstring FOR TESTING RAISING cx_static_check.
METHODS serialize_xstring FOR TESTING RAISING cx_static_check.
ENDCLASS.

CLASS ltcl_serialize IMPLEMENTATION.

METHOD serialize_empty_xstring.
DATA: BEGIN OF is_metadata,
foo TYPE xstring,
END OF is_metadata.
DATA lv_json TYPE string.
lv_json = /ui2/cl_json=>serialize( is_metadata ).

cl_abap_unit_assert=>assert_equals(
act = lv_json
exp = '{"FOO":""}' ).
ENDMETHOD.

METHOD serialize_xstring.
DATA: BEGIN OF is_metadata,
foo TYPE xstring,
END OF is_metadata.
DATA lv_json TYPE string.
is_metadata-foo = 'AA'.
lv_json = /ui2/cl_json=>serialize( is_metadata ).

cl_abap_unit_assert=>assert_equals(
act = lv_json
exp = '{"FOO":"qg=="}' ).
ENDMETHOD.

METHOD bool_false.
DATA: BEGIN OF ls_data,
foo_bar TYPE abap_bool,
Expand Down