From c1360186d9cd1932ad39493e64366f8775c2a19e Mon Sep 17 00:00:00 2001 From: Marc Bernard Date: Mon, 9 Feb 2026 13:40:15 +0000 Subject: [PATCH 1/2] fix: filter of initial numeric values Unfortunately, some tests for the filter lib are incorrectly setting initial values. The tests pass although there is a bug in the "empty filter". This fixes the "empty filter" so it correctly skips initial numeric values (i.e. `0`) and fixes the corresponding test cases. --- src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap | 5 +++-- src/libs/zcl_ajson_filter_lib.clas.testclasses.abap | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap b/src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap index 63d0dd0..0901707 100644 --- a/src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap +++ b/src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap @@ -11,8 +11,9 @@ 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 <> 'num' and is_node-value is not initial ) or " string & bool + ( iv_visit = zif_ajson_filter=>visit_type-value and is_node-type = 'num' 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. diff --git a/src/libs/zcl_ajson_filter_lib.clas.testclasses.abap b/src/libs/zcl_ajson_filter_lib.clas.testclasses.abap index b896d94..67313e6 100644 --- a/src/libs/zcl_ajson_filter_lib.clas.testclasses.abap +++ b/src/libs/zcl_ajson_filter_lib.clas.testclasses.abap @@ -26,12 +26,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 ). @@ -55,12 +57,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 ). @@ -209,12 +214,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 ). From 2b2d2384aa9aa982ed413becb04bba5bb4f1a224 Mon Sep 17 00:00:00 2001 From: Marc Bernard Date: Mon, 9 Feb 2026 13:48:40 +0000 Subject: [PATCH 2/2] lint + extend test --- src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap | 6 ++++-- src/libs/zcl_ajson_filter_lib.clas.testclasses.abap | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap b/src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap index 0901707..16f9e5d 100644 --- a/src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap +++ b/src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap @@ -11,8 +11,10 @@ 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-type <> 'num' and is_node-value is not initial ) or " string & bool - ( iv_visit = zif_ajson_filter=>visit_type-value and is_node-type = 'num' and is_node-value <> '0' ) or " num + ( 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 diff --git a/src/libs/zcl_ajson_filter_lib.clas.testclasses.abap b/src/libs/zcl_ajson_filter_lib.clas.testclasses.abap index 67313e6..3b2efd4 100644 --- a/src/libs/zcl_ajson_filter_lib.clas.testclasses.abap +++ b/src/libs/zcl_ajson_filter_lib.clas.testclasses.abap @@ -36,6 +36,13 @@ class ltcl_filters_test implementation. 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 @@ -43,7 +50,7 @@ class ltcl_filters_test implementation. 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.