sbcgua / ajson

Yet another json parser serializer for ABAP
MIT License
49 stars 15 forks source link

Mapper gets lost after filtering #176

Closed oblomov-dev closed 5 months ago

oblomov-dev commented 5 months ago

Not sure if this is an intended behaviour, but i was suprised:

    DATA:
      BEGIN OF ls_test,
        text TYPE string VALUE `ABC`,
      END OF ls_test.

    DATA(test) = zcl_ajson=>create_empty( ii_custom_mapping = zcl_abapgit_ajson_mapping=>create_upper_case( ) ).

    test->set(
        iv_path = `/`
        iv_val  = ls_test ).

    DATA(lv_result) = test->stringify( ). "{"TEXT":"ABC"}

    DATA(test_filtered) = test->filter( zcl_abapgit_ajson_filter_lib=>create_empty_filter( ) ).

    test_filtered->set(
        iv_path = `/`
        iv_val  = ls_test ).

    DATA(lv_result2) = test_filtered->stringify( ). "{"text":"ABC"}

    "expected:  "{"TEXT":"ABC"} -> mapper got lost?

The returning object of the filter fucntion does not get the mapping of the original object:

image

But maybe my understanding of the API was just wrong and everything is fine like this.

sbcgua commented 5 months ago

Sorry for late response. Well ... looks like a bug on the one hand. But on the other the ii_custom_mapping is a deprecated feature - https://github.com/sbcgua/ajson?tab=readme-ov-file#mapping-via-to_abap-and-to_json-deprecated - in favor of filter method. So I'd better not rely on this particular feature but use the filter approach instead.

oblomov-dev commented 5 months ago

ah thank you for the hint, overlooked that this is deprecated, in my specific situation i use now the following APIs and it works as i would expect:

        DATA(lo_json) =  CAST z2ui5_if_ajson( z2ui5_cl_ajson=>new( ) ).
        lo_json->set( iv_path = `/` iv_val = val ).

        IF config-custom_mapper IS BOUND.
          lo_json = lo_json->map( config-custom_mapper ).
        ELSE.
          lo_json = lo_json->map( z2ui5_cl_ajson_mapping=>create_upper_case( ) ).
        ENDIF.

        IF config-custom_filter IS BOUND.
          lo_json = lo_json->filter( config-custom_filter ).
        ELSE.
          lo_json = lo_json->filter( z2ui5_cl_ajson_filter_lib=>create_empty_filter( ) ).
        ENDIF.
sbcgua commented 5 months ago

Good to know! So the issue can be closed?

oblomov-dev commented 5 months ago

yes thanks for the help!