Skip to content

Commit

Permalink
ajson, Automatic Update (abapGit#6827)
Browse files Browse the repository at this point in the history
Co-authored-by: larshp <[email protected]>
Co-authored-by: Lars Hvam <[email protected]>
  • Loading branch information
3 people authored Feb 26, 2024
1 parent 687e431 commit 6f8a136
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/json/zcl_abapgit_ajson.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,12 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION.
ls_new_node-name = ls_split_path-name.
ls_new_node-type = zif_abapgit_ajson_types=>node_type-array.

IF ms_opts-keep_item_order = abap_true AND ls_deleted_node IS NOT INITIAL.
ls_new_node-order = ls_deleted_node-order.
IF ms_opts-keep_item_order = abap_true.
IF ls_deleted_node IS NOT INITIAL.
ls_new_node-order = ls_deleted_node-order.
ELSE.
ls_new_node-order = lr_parent->children.
ENDIF.
ENDIF.

INSERT ls_new_node INTO TABLE mt_json_tree.
Expand Down
32 changes: 32 additions & 0 deletions src/json/zcl_abapgit_ajson.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,7 @@ CLASS ltcl_writer_test DEFINITION FINAL
METHODS read_only FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS set_array_obj FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS set_with_type FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS new_array_w_keep_order_touch FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS overwrite_w_keep_order_touch FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS overwrite_w_keep_order_set FOR TESTING RAISING zcx_abapgit_ajson_error.
METHODS setx FOR TESTING RAISING zcx_abapgit_ajson_error.
Expand Down Expand Up @@ -3271,6 +3272,37 @@ CLASS ltcl_writer_test IMPLEMENTATION.

ENDMETHOD.

METHOD new_array_w_keep_order_touch.

DATA li_cut TYPE REF TO zif_abapgit_ajson.

" default order adds new arrays at beginning of node (pos 0)
li_cut = zcl_abapgit_ajson=>create_empty(
)->set(
iv_path = '/b'
iv_val = 1 ).

li_cut->touch_array( '/a' ).

cl_abap_unit_assert=>assert_equals(
act = li_cut->stringify( )
exp = '{"a":[],"b":1}' ).

" with keep order, new array is created at end of node
li_cut = zcl_abapgit_ajson=>create_empty(
)->keep_item_order(
)->set(
iv_path = '/b'
iv_val = 1 ).

li_cut->touch_array( '/a' ).

cl_abap_unit_assert=>assert_equals(
act = li_cut->stringify( )
exp = '{"b":1,"a":[]}' ).

ENDMETHOD.

METHOD overwrite_w_keep_order_touch.

DATA li_cut TYPE REF TO zif_abapgit_ajson.
Expand Down

0 comments on commit 6f8a136

Please sign in to comment.