Skip to content
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
7 changes: 5 additions & 2 deletions src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ class lcl_empty_filter implementation.
method zif_ajson_filter~keep_node.

rv_keep = boolc(
( iv_visit = zif_ajson_filter=>visit_type-value and is_node-value is not initial ) or
( iv_visit <> zif_ajson_filter=>visit_type-value and is_node-children > 0 ) ).
( iv_visit = zif_ajson_filter=>visit_type-value and
is_node-type <> zif_ajson_types=>node_type-number and is_node-value is not initial ) or " string & bool & null
( iv_visit = zif_ajson_filter=>visit_type-value and
is_node-type = zif_ajson_types=>node_type-number and is_node-value <> '0' ) or " num
( iv_visit <> zif_ajson_filter=>visit_type-value and is_node-children > 0 ) ). " array & object
" children = 0 on open for initially empty nodes and on close for filtered ones

endmethod.
Expand Down
16 changes: 15 additions & 1 deletion src/libs/zcl_ajson_filter_lib.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,31 @@ class ltcl_filters_test implementation.
iv_path = '/a'
iv_val = '1' ).
li_json->set(
iv_ignore_empty = abap_false
iv_path = '/b'
iv_val = '' ).
li_json->set(
iv_path = '/c'
iv_val = '3' ).
li_json->set(
iv_ignore_empty = abap_false
iv_path = '/d'
iv_val = 0 ).
li_json->set_boolean(
iv_path = '/e'
iv_val = abap_false ).
li_json->set_boolean(
iv_path = '/f'
iv_val = abap_true ).
li_json->set_null( '/g' ).

li_json_filtered = zcl_ajson=>create_from(
ii_source_json = li_json
ii_filter = zcl_ajson_filter_lib=>create_empty_filter( ) ).

cl_abap_unit_assert=>assert_equals(
act = li_json_filtered->stringify( )
exp = '{"a":"1","c":"3"}' ).
exp = '{"a":"1","c":"3","e":false,"f":true,"g":null}' ).

endmethod.

Expand All @@ -55,12 +64,15 @@ class ltcl_filters_test implementation.
iv_path = '/a'
iv_val = '1' ).
li_json->set(
iv_ignore_empty = abap_false
iv_path = '/b/c'
iv_val = '' ).
li_json->set(
iv_ignore_empty = abap_false
iv_path = '/b/d'
iv_val = 0 ).
li_json->set(
iv_ignore_empty = abap_false
iv_path = '/d/e'
iv_val = 0 ).

Expand Down Expand Up @@ -209,12 +221,14 @@ class ltcl_filters_test implementation.
iv_path = '/a'
iv_val = '1' ).
li_json->set(
iv_ignore_empty = abap_false
iv_path = '/b'
iv_val = '' ).
li_json->set(
iv_path = '/c'
iv_val = '3' ).
li_json->set(
iv_ignore_empty = abap_false
iv_path = '/d'
iv_val = 0 ).

Expand Down