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 committed Aug 25, 2024
1 parent fd26572 commit e7e3e68
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/#mbtools#cl_ajson.clas.locals_imp.abap
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ CLASS lcl_json_to_abap IMPLEMENTATION.
IF is_parent_type-tab_item_buf IS NOT BOUND. " Indirect hint that table was srt/hsh, see get_node_type
APPEND INITIAL LINE TO <parent_stdtab> REFERENCE INTO lr_target_field.
ASSERT sy-subrc = 0.
ELSE.
CLEAR <tab_item>.
ENDIF.

WHEN lif_kind=>struct_flat OR lif_kind=>struct_deep.
Expand Down Expand Up @@ -1809,8 +1811,13 @@ CLASS lcl_filter_runner IMPLEMENTATION.
METHOD walk.

DATA ls_node TYPE /mbtools/if_ajson_types=>ty_node.
DATA lv_tab_key TYPE string.

IF cs_parent-type = /mbtools/if_ajson_types=>node_type-array.
lv_tab_key = 'array_index'. " path + index
ENDIF.

LOOP AT mr_source_tree->* INTO ls_node WHERE path = iv_path.
LOOP AT mr_source_tree->* INTO ls_node USING KEY (lv_tab_key) WHERE path = iv_path.
CASE ls_node-type.
WHEN /mbtools/if_ajson_types=>node_type-boolean OR /mbtools/if_ajson_types=>node_type-null
OR /mbtools/if_ajson_types=>node_type-number OR /mbtools/if_ajson_types=>node_type-string.
Expand Down
214 changes: 213 additions & 1 deletion src/#mbtools#cl_ajson.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,21 @@ CLASS ltcl_json_to_abap DEFINITION
METHODS to_abap_str_to_packed
FOR TESTING
RAISING cx_static_check.
METHODS to_abap_compressed_stdrd
FOR TESTING
RAISING cx_static_check.
METHODS to_abap_compressed_stdrd_key
FOR TESTING
RAISING cx_static_check.
METHODS to_abap_compressed_sort
FOR TESTING
RAISING cx_static_check.
METHODS to_abap_compressed_sort_unique
FOR TESTING
RAISING cx_static_check.
METHODS to_abap_compressed_hash
FOR TESTING
RAISING cx_static_check.
ENDCLASS.

CLASS /mbtools/cl_ajson DEFINITION LOCAL FRIENDS ltcl_json_to_abap.
Expand Down Expand Up @@ -2189,6 +2204,171 @@ CLASS ltcl_json_to_abap IMPLEMENTATION.

ENDMETHOD.

METHOD to_abap_compressed_stdrd.

TYPES: BEGIN OF ty_foo_bar,
foo TYPE string,
bar TYPE string,
END OF ty_foo_bar.

DATA lt_foo_bar TYPE STANDARD TABLE OF ty_foo_bar.
DATA ls_foo_bar LIKE LINE OF lt_foo_bar.
DATA lo_ajson TYPE REF TO /mbtools/cl_ajson.
DATA lv_json TYPE string.

lv_json =
'[' &&
' {' &&
' "foo": "abc",' &&
' "bar": "123"' &&
' },' &&
' {' &&
' "foo": "cde"' &&
' }' &&
']'.

lo_ajson = /mbtools/cl_ajson=>parse( lv_json ).

lo_ajson->to_abap( IMPORTING ev_container = lt_foo_bar ).

READ TABLE lt_foo_bar WITH KEY foo = 'cde' INTO ls_foo_bar.

cl_abap_unit_assert=>assert_initial( act = ls_foo_bar-bar ).

ENDMETHOD.

METHOD to_abap_compressed_stdrd_key.

TYPES: BEGIN OF ty_foo_bar,
foo TYPE string,
bar TYPE string,
END OF ty_foo_bar.

DATA lt_foo_bar TYPE STANDARD TABLE OF ty_foo_bar WITH NON-UNIQUE KEY foo.
DATA ls_foo_bar LIKE LINE OF lt_foo_bar.
DATA lo_ajson TYPE REF TO /mbtools/cl_ajson.
DATA lv_json TYPE string.

lv_json =
'[' &&
' {' &&
' "foo": "abc",' &&
' "bar": "123"' &&
' },' &&
' {' &&
' "foo": "cde"' &&
' }' &&
']'.

lo_ajson = /mbtools/cl_ajson=>parse( lv_json ).

lo_ajson->to_abap( IMPORTING ev_container = lt_foo_bar ).

READ TABLE lt_foo_bar WITH KEY foo = 'cde' INTO ls_foo_bar.

cl_abap_unit_assert=>assert_initial( act = ls_foo_bar-bar ).

ENDMETHOD.

METHOD to_abap_compressed_sort.

TYPES: BEGIN OF ty_foo_bar,
foo TYPE string,
bar TYPE string,
END OF ty_foo_bar.

DATA lt_foo_bar TYPE SORTED TABLE OF ty_foo_bar WITH NON-UNIQUE KEY foo.
DATA ls_foo_bar LIKE LINE OF lt_foo_bar.
DATA lo_ajson TYPE REF TO /mbtools/cl_ajson.
DATA lv_json TYPE string.

lv_json =
'[' &&
' {' &&
' "foo": "abc",' &&
' "bar": "123"' &&
' },' &&
' {' &&
' "foo": "cde"' &&
' }' &&
']'.

lo_ajson = /mbtools/cl_ajson=>parse( lv_json ).

lo_ajson->to_abap( IMPORTING ev_container = lt_foo_bar ).

READ TABLE lt_foo_bar WITH KEY foo = 'cde' INTO ls_foo_bar.

cl_abap_unit_assert=>assert_initial( act = ls_foo_bar-bar ).

ENDMETHOD.

METHOD to_abap_compressed_sort_unique.

TYPES: BEGIN OF ty_foo_bar,
foo TYPE string,
bar TYPE string,
END OF ty_foo_bar.

DATA lt_foo_bar TYPE SORTED TABLE OF ty_foo_bar WITH UNIQUE KEY foo.
DATA ls_foo_bar LIKE LINE OF lt_foo_bar.
DATA lo_ajson TYPE REF TO /mbtools/cl_ajson.
DATA lv_json TYPE string.

lv_json =
'[' &&
' {' &&
' "foo": "abc",' &&
' "bar": "123"' &&
' },' &&
' {' &&
' "foo": "cde"' &&
' }' &&
']'.

lo_ajson = /mbtools/cl_ajson=>parse( lv_json ).

lo_ajson->to_abap( IMPORTING ev_container = lt_foo_bar ).

READ TABLE lt_foo_bar WITH KEY foo = 'cde' INTO ls_foo_bar.

cl_abap_unit_assert=>assert_initial( act = ls_foo_bar-bar ).

ENDMETHOD.

METHOD to_abap_compressed_hash.

TYPES: BEGIN OF ty_foo_bar,
foo TYPE string,
bar TYPE string,
END OF ty_foo_bar.

DATA lt_foo_bar TYPE HASHED TABLE OF ty_foo_bar WITH UNIQUE KEY foo.
DATA ls_foo_bar LIKE LINE OF lt_foo_bar.
DATA lo_ajson TYPE REF TO /mbtools/cl_ajson.
DATA lv_json TYPE string.

lv_json =
'[' &&
' {' &&
' "foo": "abc",' &&
' "bar": "123"' &&
' },' &&
' {' &&
' "foo": "cde"' &&
' }' &&
']'.

lo_ajson = /mbtools/cl_ajson=>parse( lv_json ).

lo_ajson->to_abap( IMPORTING ev_container = lt_foo_bar ).

READ TABLE lt_foo_bar WITH KEY foo = 'cde' INTO ls_foo_bar.

cl_abap_unit_assert=>assert_initial( act = ls_foo_bar-bar ).

ENDMETHOD.

ENDCLASS.

**********************************************************************
Expand Down Expand Up @@ -4408,15 +4588,47 @@ CLASS ltcl_filter_test IMPLEMENTATION.
lo_json->push(
iv_path = '/'
iv_val = 'b' ).
lo_json->push(
iv_path = '/'
iv_val = 'c' ).
lo_json->push(
iv_path = '/'
iv_val = 'd' ).
lo_json->push(
iv_path = '/'
iv_val = 'e' ).
lo_json->push(
iv_path = '/'
iv_val = 'f' ).
lo_json->push(
iv_path = '/'
iv_val = 'g' ).
lo_json->push(
iv_path = '/'
iv_val = 'h' ).
lo_json->push(
iv_path = '/'
iv_val = 'i' ).
lo_json->push(
iv_path = '/'
iv_val = 'j' ).

lo_json_filtered = /mbtools/cl_ajson=>create_from(
ii_source_json = lo_json
ii_filter = me ).

CREATE OBJECT lo_nodes_exp.
lo_nodes_exp->add( ' | |array | | |2' ).
lo_nodes_exp->add( ' | |array | | |10' ).
lo_nodes_exp->add( '/ |1 |str |a |1|0' ).
lo_nodes_exp->add( '/ |2 |str |b |2|0' ).
lo_nodes_exp->add( '/ |3 |str |c |3|0' ).
lo_nodes_exp->add( '/ |4 |str |d |4|0' ).
lo_nodes_exp->add( '/ |5 |str |e |5|0' ).
lo_nodes_exp->add( '/ |6 |str |f |6|0' ).
lo_nodes_exp->add( '/ |7 |str |g |7|0' ).
lo_nodes_exp->add( '/ |8 |str |h |8|0' ).
lo_nodes_exp->add( '/ |9 |str |i |9|0' ).
lo_nodes_exp->add( '/ |10 |str |j |10|0' ).

cl_abap_unit_assert=>assert_equals(
act = lo_json_filtered->mt_json_tree
Expand Down

0 comments on commit e7e3e68

Please sign in to comment.