ajson, Automatic Update (#6405)

Co-authored-by: larshp <larshp@users.noreply.github.com>
Co-authored-by: Marc Bernard <59966492+mbtools@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2023-08-15 17:14:34 +02:00 committed by GitHub
parent 2d3e9fffd1
commit 1a5e0813c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 64 deletions

View File

@ -1211,7 +1211,6 @@ CLASS lcl_abap_to_json DEFINITION FINAL.
iv_item_order TYPE i DEFAULT 0
CHANGING
ct_nodes TYPE zif_abapgit_ajson_types=>ty_nodes_tt
cs_root TYPE zif_abapgit_ajson_types=>ty_node OPTIONAL
RAISING
zcx_abapgit_ajson_error.
@ -1497,7 +1496,7 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
METHOD convert_struc.
DATA lo_struc TYPE REF TO cl_abap_structdescr.
DATA lt_comps TYPE cl_abap_structdescr=>component_table.
DATA lt_comps TYPE cl_abap_structdescr=>included_view.
DATA ls_next_prefix LIKE is_prefix.
DATA lv_mapping_prefix_name LIKE is_prefix-name.
DATA lv_item_order TYPE i.
@ -1509,34 +1508,30 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
" Object root
IF cs_root IS SUPPLIED. " call for include structure
ASSIGN cs_root TO <root>.
ELSE. " First call
ls_root-path = is_prefix-path.
ls_root-name = is_prefix-name.
ls_root-type = zif_abapgit_ajson_types=>node_type-object.
ls_root-index = iv_index.
IF mi_custom_mapping IS BOUND.
ls_root-name = mi_custom_mapping->to_json(
iv_path = is_prefix-path
iv_name = is_prefix-name ).
ENDIF.
IF ls_root-name IS INITIAL.
ls_root-name = is_prefix-name.
ENDIF.
ls_root-order = iv_item_order.
APPEND ls_root TO ct_nodes ASSIGNING <root>.
ls_root-path = is_prefix-path.
ls_root-name = is_prefix-name.
ls_root-type = zif_abapgit_ajson_types=>node_type-object.
ls_root-index = iv_index.
IF mi_custom_mapping IS BOUND.
ls_root-name = mi_custom_mapping->to_json(
iv_path = is_prefix-path
iv_name = is_prefix-name ).
ENDIF.
IF ls_root-name IS INITIAL.
ls_root-name = is_prefix-name.
ENDIF.
ls_root-order = iv_item_order.
APPEND ls_root TO ct_nodes ASSIGNING <root>.
" Object attributes
lo_struc ?= io_type.
lt_comps = lo_struc->get_components( ).
lt_comps = lo_struc->get_included_view( ).
" replaced call to get_components() with get_included_view() to avoid problems with suffixes in includes.
" get_components is potentially much slower than lo_struc->components
" but ! we still need it to identify booleans
" and rtti seems to cache type descriptions really well (https://github.com/sbcgua/benchmarks.git)
@ -1547,48 +1542,33 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
LOOP AT lt_comps ASSIGNING <c>.
CLEAR lv_mapping_prefix_name.
IF <c>-as_include = abap_true.
convert_struc(
EXPORTING
iv_data = iv_data
io_type = <c>-type
is_prefix = is_prefix
CHANGING
cs_root = <root>
ct_nodes = ct_nodes ).
ELSE.
<root>-children = <root>-children + 1.
ls_next_prefix-name = to_lower( <c>-name ).
ASSIGN COMPONENT <c>-name OF STRUCTURE iv_data TO <val>.
ASSERT sy-subrc = 0.
IF mi_custom_mapping IS BOUND AND <c>-type->kind = cl_abap_typedescr=>kind_elem.
lv_mapping_prefix_name = mi_custom_mapping->to_json( iv_path = ls_next_prefix-path
iv_name = ls_next_prefix-name ).
ENDIF.
IF lv_mapping_prefix_name IS NOT INITIAL.
ls_next_prefix-name = lv_mapping_prefix_name.
ENDIF.
IF mv_keep_item_order = abap_true.
lv_item_order = <root>-children.
ENDIF.
convert_any(
EXPORTING
iv_data = <val>
io_type = <c>-type
is_prefix = ls_next_prefix
iv_item_order = lv_item_order
CHANGING
ct_nodes = ct_nodes ).
<root>-children = <root>-children + 1.
ls_next_prefix-name = to_lower( <c>-name ).
ASSIGN COMPONENT <c>-name OF STRUCTURE iv_data TO <val>.
ASSERT sy-subrc = 0.
IF mi_custom_mapping IS BOUND AND <c>-type->kind = cl_abap_typedescr=>kind_elem.
lv_mapping_prefix_name = mi_custom_mapping->to_json( iv_path = ls_next_prefix-path
iv_name = ls_next_prefix-name ).
ENDIF.
IF lv_mapping_prefix_name IS NOT INITIAL.
ls_next_prefix-name = lv_mapping_prefix_name.
ENDIF.
IF mv_keep_item_order = abap_true.
lv_item_order = <root>-children.
ENDIF.
convert_any(
EXPORTING
iv_data = <val>
io_type = <c>-type
is_prefix = ls_next_prefix
iv_item_order = lv_item_order
CHANGING
ct_nodes = ct_nodes ).
ENDLOOP.
ENDMETHOD.

View File

@ -3825,6 +3825,13 @@ CLASS ltcl_abap_to_json DEFINITION
stab TYPE string_table,
END OF ty_struc_complex.
TYPES
BEGIN OF ty_named_include.
INCLUDE TYPE ty_struc AS named_with_suffix RENAMING WITH SUFFIX _suf.
TYPES:
el TYPE string,
END OF ty_named_include.
METHODS set_ajson FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS set_value_number FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS set_value_string FOR TESTING RAISING zcx_abapgit_ajson_error.
@ -3837,6 +3844,7 @@ CLASS ltcl_abap_to_json DEFINITION
METHODS set_obj FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS set_array FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS set_complex_obj FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS set_include_with_suffix FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS prefix FOR TESTING RAISING zcx_abapgit_ajson_error.
ENDCLASS.
@ -4117,6 +4125,34 @@ CLASS ltcl_abap_to_json IMPLEMENTATION.
ENDMETHOD.
METHOD set_include_with_suffix.
DATA lo_nodes_exp TYPE REF TO lcl_nodes_helper.
DATA ls_struc TYPE ty_named_include.
DATA lt_nodes TYPE zif_abapgit_ajson_types=>ty_nodes_tt.
ls_struc-a_suf = 'abc'.
ls_struc-b_suf = 10.
ls_struc-c_suf = abap_true.
ls_struc-d_suf = 'X'.
ls_struc-el = 'elem'.
CREATE OBJECT lo_nodes_exp.
lo_nodes_exp->add( ' | |object | ||5' ).
lo_nodes_exp->add( '/ |a_suf |str |abc ||0' ).
lo_nodes_exp->add( '/ |b_suf |num |10 ||0' ).
lo_nodes_exp->add( '/ |c_suf |bool |true ||0' ).
lo_nodes_exp->add( '/ |d_suf |bool |true ||0' ).
lo_nodes_exp->add( '/ |el |str |elem ||0' ).
lt_nodes = lcl_abap_to_json=>convert( iv_data = ls_struc ).
cl_abap_unit_assert=>assert_equals(
act = lt_nodes
exp = lo_nodes_exp->mt_nodes ).
ENDMETHOD.
METHOD set_array.
DATA lo_nodes_exp TYPE REF TO lcl_nodes_helper.

View File

@ -1,7 +1,7 @@
INTERFACE zif_abapgit_ajson
PUBLIC.
CONSTANTS version TYPE string VALUE 'v1.1.8'. "#EC NOTEXT
CONSTANTS version TYPE string VALUE 'v1.1.9'. "#EC NOTEXT
CONSTANTS origin TYPE string VALUE 'https://github.com/sbcgua/ajson'. "#EC NOTEXT
CONSTANTS license TYPE string VALUE 'MIT'. "#EC NOTEXT