Skip to content

Commit

Permalink
[create-pull-request] automated change
Browse files Browse the repository at this point in the history
  • Loading branch information
mbtools authored Apr 7, 2024
1 parent 69f6b0f commit 14f3432
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/json/#mbtools#cl_ajson.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,12 @@ CLASS /mbtools/cl_ajson IMPLEMENTATION.
ls_new_node-name = ls_split_path-name.
ls_new_node-type = /mbtools/if_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
19 changes: 13 additions & 6 deletions src/json/#mbtools#cl_ajson.clas.locals_imp.abap
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,19 @@ CLASS lcl_json_to_abap IMPLEMENTATION.

WHEN /mbtools/if_ajson_types=>node_type-string.
" TODO: check type ?
IF is_node_type-type_kind = lif_kind=>date AND is_node-value IS NOT INITIAL.
<container> = to_date( is_node-value ).
ELSEIF is_node_type-type_kind = lif_kind=>time AND is_node-value IS NOT INITIAL.
<container> = to_time( is_node-value ).
ELSEIF is_node_type-type_kind = lif_kind=>packed AND is_node-value IS NOT INITIAL.
<container> = to_timestamp( is_node-value ).
IF is_node-value IS NOT INITIAL.
IF is_node_type-type_kind = lif_kind=>date.
<container> = to_date( is_node-value ).
ELSEIF is_node_type-type_kind = lif_kind=>time.
<container> = to_time( is_node-value ).
ELSEIF is_node_type-dd->absolute_name = '\TYPE=TIMESTAMP'
OR is_node_type-dd->absolute_name = '\TYPE=TIMESTAMPL'.
<container> = to_timestamp( is_node-value ).
ELSEIF is_node_type-type_kind = lif_kind=>packed. " Number as a string, but not a timestamp
<container> = is_node-value.
ELSE.
<container> = is_node-value.
ENDIF.
ELSE.
<container> = is_node-value.
ENDIF.
Expand Down
60 changes: 60 additions & 0 deletions src/json/#mbtools#cl_ajson.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,7 @@ CLASS ltcl_json_to_abap DEFINITION
timestamp1 TYPE timestamp,
timestamp2 TYPE timestamp,
timestamp3 TYPE timestamp,
timestamp4 TYPE timestampl,
END OF ty_complex.

METHODS to_abap_struc
Expand Down Expand Up @@ -1462,6 +1463,9 @@ CLASS ltcl_json_to_abap DEFINITION
METHODS to_abap_time
FOR TESTING
RAISING cx_static_check.
METHODS to_abap_str_to_packed
FOR TESTING
RAISING cx_static_check.
ENDCLASS.

CLASS /mbtools/cl_ajson DEFINITION LOCAL FRIENDS ltcl_json_to_abap.
Expand Down Expand Up @@ -1491,6 +1495,7 @@ CLASS ltcl_json_to_abap IMPLEMENTATION.
lo_nodes->add( '/ |timestamp1 |str |2020-07-28T00:00:00 | ' ).
lo_nodes->add( '/ |timestamp2 |str |2020-07-28T00:00:00Z | ' ).
lo_nodes->add( '/ |timestamp3 |str |2020-07-28T01:00:00+01:00 | ' ).
lo_nodes->add( '/ |timestamp4 |str |2020-07-28T01:00:00+01:00 | ' ).

CREATE OBJECT lo_cut.
lo_cut->to_abap(
Expand All @@ -1509,6 +1514,7 @@ CLASS ltcl_json_to_abap IMPLEMENTATION.
ls_exp-timestamp1 = lv_exp_timestamp.
ls_exp-timestamp2 = lv_exp_timestamp.
ls_exp-timestamp3 = lv_exp_timestamp.
ls_exp-timestamp4 = lv_exp_timestamp.

cl_abap_unit_assert=>assert_equals(
act = ls_mock
Expand Down Expand Up @@ -1576,6 +1582,28 @@ CLASS ltcl_json_to_abap IMPLEMENTATION.

ENDMETHOD.

METHOD to_abap_str_to_packed.

DATA lo_cut TYPE REF TO lcl_json_to_abap.
DATA lv_act TYPE p LENGTH 10 DECIMALS 3.
DATA lo_nodes TYPE REF TO lcl_nodes_helper.

CREATE OBJECT lo_nodes.
lo_nodes->add( ' | |str |1.3333 | ' ).

CREATE OBJECT lo_cut.
lo_cut->to_abap(
EXPORTING
it_nodes = lo_nodes->sorted( )
CHANGING
c_container = lv_act ).

cl_abap_unit_assert=>assert_equals(
act = lv_act
exp = '1.333' ).

ENDMETHOD.

METHOD to_abap_value.

DATA lo_cut TYPE REF TO lcl_json_to_abap.
Expand Down Expand Up @@ -2198,6 +2226,7 @@ CLASS ltcl_writer_test DEFINITION FINAL
METHODS read_only FOR TESTING RAISING /mbtools/cx_ajson_error.
METHODS set_array_obj FOR TESTING RAISING /mbtools/cx_ajson_error.
METHODS set_with_type FOR TESTING RAISING /mbtools/cx_ajson_error.
METHODS new_array_w_keep_order_touch FOR TESTING RAISING /mbtools/cx_ajson_error.
METHODS overwrite_w_keep_order_touch FOR TESTING RAISING /mbtools/cx_ajson_error.
METHODS overwrite_w_keep_order_set FOR TESTING RAISING /mbtools/cx_ajson_error.
METHODS setx FOR TESTING RAISING /mbtools/cx_ajson_error.
Expand Down Expand Up @@ -3271,6 +3300,37 @@ CLASS ltcl_writer_test IMPLEMENTATION.

ENDMETHOD.

METHOD new_array_w_keep_order_touch.

DATA li_cut TYPE REF TO /mbtools/if_ajson.

" default order adds new arrays at beginning of node (pos 0)
li_cut = /mbtools/cl_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 = /mbtools/cl_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 /mbtools/if_ajson.
Expand Down

0 comments on commit 14f3432

Please sign in to comment.