diff --git a/.github/workflows/ajson_mirror.yaml b/.github/workflows/ajson_mirror.yaml new file mode 100644 index 00000000..5539bbc5 --- /dev/null +++ b/.github/workflows/ajson_mirror.yaml @@ -0,0 +1,43 @@ +name: ajson mirror + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * 1' + +permissions: + contents: read + +jobs: + pr_ajson_changes: + # Origin repo only + permissions: + contents: write # for peter-evans/create-pull-request to create branch + pull-requests: write # for peter-evans/create-pull-request to create a PR + if: github.repository == 'abap2UI5/abap2UI5' + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - name: run + run: | + git clone https://github.com/abap2UI5/ajson_mirror.git + ls -l + rm src/01/00/01/z* + cp ajson_mirror/src/z* src/01/00/01/ + rm -rf ajson_mirror + git status + - name: Open PR + uses: peter-evans/create-pull-request@v3 + with: + title: ajson, Automatic Update + branch: automatic/ajson + body: | + Automatic update from mirror + https://github.com/abap2UI5/ajson_mirror + + Make manual change to trigger CI + + Note: manual changes might be overwritten when the branch updates, so keep changes small, and merge fast \ No newline at end of file diff --git a/src/01/00/01/z2ui5_cl_ajson.clas.abap b/src/01/00/01/z2ui5_cl_ajson.clas.abap index 85e27419..2a068437 100644 --- a/src/01/00/01/z2ui5_cl_ajson.clas.abap +++ b/src/01/00/01/z2ui5_cl_ajson.clas.abap @@ -1,372 +1,372 @@ -class z2ui5_cl_ajson definition - public - create public . +CLASS z2ui5_cl_ajson DEFINITION + PUBLIC + CREATE PUBLIC . - public section. + PUBLIC SECTION. - interfaces z2ui5_if_ajson . + INTERFACES z2ui5_if_ajson . - aliases: - is_empty for z2ui5_if_ajson~is_empty, - exists for z2ui5_if_ajson~exists, - members for z2ui5_if_ajson~members, - get for z2ui5_if_ajson~get, - get_boolean for z2ui5_if_ajson~get_boolean, - get_integer for z2ui5_if_ajson~get_integer, - get_number for z2ui5_if_ajson~get_number, - get_date for z2ui5_if_ajson~get_date, - get_timestamp for z2ui5_if_ajson~get_timestamp, - get_string for z2ui5_if_ajson~get_string, - slice for z2ui5_if_ajson~slice, - to_abap for z2ui5_if_ajson~to_abap, - array_to_string_table for z2ui5_if_ajson~array_to_string_table. + ALIASES: + is_empty FOR z2ui5_if_ajson~is_empty, + exists FOR z2ui5_if_ajson~exists, + members FOR z2ui5_if_ajson~members, + get FOR z2ui5_if_ajson~get, + get_boolean FOR z2ui5_if_ajson~get_boolean, + get_integer FOR z2ui5_if_ajson~get_integer, + get_number FOR z2ui5_if_ajson~get_number, + get_date FOR z2ui5_if_ajson~get_date, + get_timestamp FOR z2ui5_if_ajson~get_timestamp, + get_string FOR z2ui5_if_ajson~get_string, + slice FOR z2ui5_if_ajson~slice, + to_abap FOR z2ui5_if_ajson~to_abap, + array_to_string_table FOR z2ui5_if_ajson~array_to_string_table. - aliases: - clear for z2ui5_if_ajson~clear, - set for z2ui5_if_ajson~set, - setx for z2ui5_if_ajson~setx, - set_boolean for z2ui5_if_ajson~set_boolean, - set_string for z2ui5_if_ajson~set_string, - set_integer for z2ui5_if_ajson~set_integer, - set_date for z2ui5_if_ajson~set_date, - set_timestamp for z2ui5_if_ajson~set_timestamp, - set_null for z2ui5_if_ajson~set_null, - delete for z2ui5_if_ajson~delete, - touch_array for z2ui5_if_ajson~touch_array, - push for z2ui5_if_ajson~push, - stringify for z2ui5_if_ajson~stringify. + ALIASES: + clear FOR z2ui5_if_ajson~clear, + set FOR z2ui5_if_ajson~set, + setx FOR z2ui5_if_ajson~setx, + set_boolean FOR z2ui5_if_ajson~set_boolean, + set_string FOR z2ui5_if_ajson~set_string, + set_integer FOR z2ui5_if_ajson~set_integer, + set_date FOR z2ui5_if_ajson~set_date, + set_timestamp FOR z2ui5_if_ajson~set_timestamp, + set_null FOR z2ui5_if_ajson~set_null, + delete FOR z2ui5_if_ajson~delete, + touch_array FOR z2ui5_if_ajson~touch_array, + push FOR z2ui5_if_ajson~push, + stringify FOR z2ui5_if_ajson~stringify. - aliases: - clone for z2ui5_if_ajson~clone, - filter for z2ui5_if_ajson~filter, - map for z2ui5_if_ajson~map. + ALIASES: + clone FOR z2ui5_if_ajson~clone, + filter FOR z2ui5_if_ajson~filter, + map FOR z2ui5_if_ajson~map. - aliases: - mt_json_tree for z2ui5_if_ajson~mt_json_tree, - keep_item_order for z2ui5_if_ajson~keep_item_order, - format_datetime for z2ui5_if_ajson~format_datetime, - to_abap_corresponding_only for z2ui5_if_ajson~to_abap_corresponding_only, - freeze for z2ui5_if_ajson~freeze. + ALIASES: + mt_json_tree FOR z2ui5_if_ajson~mt_json_tree, + keep_item_order FOR z2ui5_if_ajson~keep_item_order, + format_datetime FOR z2ui5_if_ajson~format_datetime, + to_abap_corresponding_only FOR z2ui5_if_ajson~to_abap_corresponding_only, + freeze FOR z2ui5_if_ajson~freeze. - class-methods parse - importing - !iv_json type string - !iv_freeze type abap_bool default abap_false - !ii_custom_mapping type ref to z2ui5_if_ajson_mapping optional - !iv_keep_item_order type abap_bool default abap_false - returning - value(ro_instance) type ref to z2ui5_cl_ajson - raising - z2UI5_cx_ajson_error . + CLASS-METHODS parse + IMPORTING + !iv_json TYPE string + !iv_freeze TYPE abap_bool DEFAULT abap_false + !ii_custom_mapping TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL + !iv_keep_item_order TYPE abap_bool DEFAULT abap_false + RETURNING + VALUE(ro_instance) TYPE REF TO z2ui5_cl_ajson + RAISING + z2ui5_cx_ajson_error . - class-methods create_empty " Might be deprecated, prefer using new( ) or create object - importing - !ii_custom_mapping type ref to z2ui5_if_ajson_mapping optional - iv_keep_item_order type abap_bool default abap_false - iv_format_datetime type abap_bool default abap_true - iv_to_abap_corresponding_only type abap_bool default abap_false - returning - value(ro_instance) type ref to z2ui5_cl_ajson. + CLASS-METHODS create_empty " Might be deprecated, prefer using new( ) or create object + IMPORTING + !ii_custom_mapping TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL + iv_keep_item_order TYPE abap_bool DEFAULT abap_false + iv_format_datetime TYPE abap_bool DEFAULT abap_true + iv_to_abap_corresponding_only TYPE abap_bool DEFAULT abap_false + RETURNING + VALUE(ro_instance) TYPE REF TO z2ui5_cl_ajson. " Experimental ! May change - class-methods create_from " TODO, rename to 'from' ? - importing - !ii_source_json type ref to z2ui5_if_ajson - !ii_filter type ref to z2ui5_if_ajson_filter optional " Might be deprecated, use filter() instead - !ii_mapper type ref to z2ui5_if_ajson_mapping optional " Might be deprecated, use map() instead - returning - value(ro_instance) type ref to z2ui5_cl_ajson - raising - z2UI5_cx_ajson_error . + CLASS-METHODS create_from " TODO, rename to 'from' ? + IMPORTING + !ii_source_json TYPE REF TO z2ui5_if_ajson + !ii_filter TYPE REF TO z2ui5_if_ajson_filter OPTIONAL " Might be deprecated, use filter() instead + !ii_mapper TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL " Might be deprecated, use map() instead + RETURNING + VALUE(ro_instance) TYPE REF TO z2ui5_cl_ajson + RAISING + z2ui5_cx_ajson_error . - methods constructor - importing - iv_keep_item_order type abap_bool default abap_false - iv_format_datetime type abap_bool default abap_true - iv_to_abap_corresponding_only type abap_bool default abap_false. - class-methods new - importing - iv_keep_item_order type abap_bool default abap_false - iv_format_datetime type abap_bool default abap_true - iv_to_abap_corresponding_only type abap_bool default abap_false - returning - value(ro_instance) type ref to z2ui5_cl_ajson. + METHODS constructor + IMPORTING + iv_keep_item_order TYPE abap_bool DEFAULT abap_false + iv_format_datetime TYPE abap_bool DEFAULT abap_true + iv_to_abap_corresponding_only TYPE abap_bool DEFAULT abap_false. + CLASS-METHODS new + IMPORTING + iv_keep_item_order TYPE abap_bool DEFAULT abap_false + iv_format_datetime TYPE abap_bool DEFAULT abap_true + iv_to_abap_corresponding_only TYPE abap_bool DEFAULT abap_false + RETURNING + VALUE(ro_instance) TYPE REF TO z2ui5_cl_ajson. - protected section. + PROTECTED SECTION. - private section. + PRIVATE SECTION. - class-data go_float_regex type ref to cl_abap_regex. + CLASS-DATA go_float_regex TYPE REF TO cl_abap_regex. - data ms_opts type z2ui5_if_ajson=>ty_opts. - data mi_custom_mapping type ref to z2ui5_if_ajson_mapping. " DEPRECATED, will be removed + DATA ms_opts TYPE z2ui5_if_ajson=>ty_opts. + DATA mi_custom_mapping TYPE REF TO z2ui5_if_ajson_mapping. " DEPRECATED, will be removed - methods get_item - importing - iv_path type string - returning - value(rv_item) type ref to z2ui5_if_ajson_types=>ty_node. - methods prove_path_exists - importing - iv_path type string - returning - value(rr_end_node) type ref to z2ui5_if_ajson_types=>ty_node - raising - z2UI5_cx_ajson_error. - methods delete_subtree - importing - iv_path type string - iv_name type string - ir_parent type ref to z2ui5_if_ajson_types=>ty_node optional - returning - value(rs_top_node) type z2ui5_if_ajson_types=>ty_node. - methods read_only_watchdog - raising - z2UI5_cx_ajson_error. + METHODS get_item + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_item) TYPE REF TO z2ui5_if_ajson_types=>ty_node. + METHODS prove_path_exists + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rr_end_node) TYPE REF TO z2ui5_if_ajson_types=>ty_node + RAISING + z2ui5_cx_ajson_error. + METHODS delete_subtree + IMPORTING + iv_path TYPE string + iv_name TYPE string + ir_parent TYPE REF TO z2ui5_if_ajson_types=>ty_node OPTIONAL + RETURNING + VALUE(rs_top_node) TYPE z2ui5_if_ajson_types=>ty_node. + METHODS read_only_watchdog + RAISING + z2ui5_cx_ajson_error. ENDCLASS. -CLASS Z2UI5_CL_AJSON IMPLEMENTATION. +CLASS z2ui5_cl_ajson IMPLEMENTATION. - method constructor. + METHOD constructor. ms_opts-keep_item_order = iv_keep_item_order. ms_opts-to_abap_corresponding_only = iv_to_abap_corresponding_only. format_datetime( iv_format_datetime ). - endmethod. + ENDMETHOD. - method create_empty. - create object ro_instance - exporting + METHOD create_empty. + CREATE OBJECT ro_instance + EXPORTING iv_to_abap_corresponding_only = iv_to_abap_corresponding_only iv_format_datetime = iv_format_datetime iv_keep_item_order = iv_keep_item_order. ro_instance->mi_custom_mapping = ii_custom_mapping. - endmethod. + ENDMETHOD. - method create_from. + METHOD create_from. - data lo_mutator_queue type ref to lcl_mutator_queue. + DATA lo_mutator_queue TYPE REF TO lcl_mutator_queue. - if ii_source_json is not bound. - z2UI5_cx_ajson_error=>raise( 'Source not bound' ). - endif. + IF ii_source_json IS NOT BOUND. + z2ui5_cx_ajson_error=>raise( 'Source not bound' ). + ENDIF. - create object ro_instance - exporting + CREATE OBJECT ro_instance + EXPORTING iv_to_abap_corresponding_only = ii_source_json->opts( )-to_abap_corresponding_only iv_format_datetime = ii_source_json->opts( )-format_datetime iv_keep_item_order = ii_source_json->opts( )-keep_item_order. - if ii_filter is not bound and ii_mapper is not bound. + IF ii_filter IS NOT BOUND AND ii_mapper IS NOT BOUND. ro_instance->mt_json_tree = ii_source_json->mt_json_tree. - else. - create object lo_mutator_queue. - if ii_mapper is bound. + ELSE. + CREATE OBJECT lo_mutator_queue. + IF ii_mapper IS BOUND. " Mapping goes first. But maybe it should be a freely definable queue of processors ? lo_mutator_queue->add( lcl_mapper_runner=>new( ii_mapper ) ). - endif. - if ii_filter is bound. + ENDIF. + IF ii_filter IS BOUND. lo_mutator_queue->add( lcl_filter_runner=>new( ii_filter ) ). - endif. + ENDIF. lo_mutator_queue->lif_mutator_runner~run( - exporting + EXPORTING it_source_tree = ii_source_json->mt_json_tree - importing + IMPORTING et_dest_tree = ro_instance->mt_json_tree ). - endif. + ENDIF. - endmethod. + ENDMETHOD. - method delete_subtree. + METHOD delete_subtree. - data lv_parent_path type string. - data lr_parent like ir_parent. + DATA lv_parent_path TYPE string. + DATA lr_parent LIKE ir_parent. - read table mt_json_tree into rs_top_node - with key + READ TABLE mt_json_tree INTO rs_top_node + WITH KEY path = iv_path name = iv_name. - if sy-subrc <> 0. - return. " Not found ? nothing to delete ! - endif. + IF sy-subrc <> 0. + RETURN. " Not found ? nothing to delete ! + ENDIF. - delete mt_json_tree index sy-tabix. " where path = iv_path and name = iv_name. + DELETE mt_json_tree INDEX sy-tabix. " where path = iv_path and name = iv_name. - if rs_top_node-children > 0. " only for objects and arrays + IF rs_top_node-children > 0. " only for objects and arrays lv_parent_path = iv_path && iv_name && '/*'. - delete mt_json_tree where path cp lv_parent_path. - endif. + DELETE mt_json_tree WHERE path CP lv_parent_path. + ENDIF. " decrement parent children - if ir_parent is supplied. + IF ir_parent IS SUPPLIED. ir_parent->children = ir_parent->children - 1. - else. + ELSE. lr_parent = get_item( iv_path ). - if lr_parent is not initial. + IF lr_parent IS NOT INITIAL. lr_parent->children = lr_parent->children - 1. - endif. - endif. + ENDIF. + ENDIF. - endmethod. + ENDMETHOD. - method get_item. + METHOD get_item. - field-symbols like line of mt_json_tree. - data ls_path_name type z2ui5_if_ajson_types=>ty_path_name. + FIELD-SYMBOLS LIKE LINE OF mt_json_tree. + DATA ls_path_name TYPE z2ui5_if_ajson_types=>ty_path_name. ls_path_name = lcl_utils=>split_path( iv_path ). - read table mt_json_tree - assigning - with key + READ TABLE mt_json_tree + ASSIGNING + WITH KEY path = ls_path_name-path name = ls_path_name-name. - if sy-subrc = 0. - get reference of into rv_item. - endif. + IF sy-subrc = 0. + GET REFERENCE OF INTO rv_item. + ENDIF. - endmethod. + ENDMETHOD. - method new. - create object ro_instance - exporting + METHOD new. + CREATE OBJECT ro_instance + EXPORTING iv_to_abap_corresponding_only = iv_to_abap_corresponding_only iv_format_datetime = iv_format_datetime iv_keep_item_order = iv_keep_item_order. - endmethod. + ENDMETHOD. - method parse. + METHOD parse. - data lo_parser type ref to lcl_json_parser. + DATA lo_parser TYPE REF TO lcl_json_parser. - create object ro_instance. - create object lo_parser. + CREATE OBJECT ro_instance. + CREATE OBJECT lo_parser. ro_instance->mt_json_tree = lo_parser->parse( iv_json = iv_json iv_keep_item_order = iv_keep_item_order ). ro_instance->mi_custom_mapping = ii_custom_mapping. ro_instance->ms_opts-keep_item_order = iv_keep_item_order. - if iv_freeze = abap_true. + IF iv_freeze = abap_true. ro_instance->freeze( ). - endif. + ENDIF. - endmethod. + ENDMETHOD. - method prove_path_exists. + METHOD prove_path_exists. - data lt_path type string_table. - data lr_node_parent like rr_end_node. - data lv_cur_path type string. - data lv_cur_name type string. - data ls_new_node like line of mt_json_tree. + DATA lt_path TYPE string_table. + DATA lr_node_parent LIKE rr_end_node. + DATA lv_cur_path TYPE string. + DATA lv_cur_name TYPE string. + DATA ls_new_node LIKE LINE OF mt_json_tree. - split iv_path at '/' into table lt_path. - delete lt_path where table_line is initial. + SPLIT iv_path AT '/' INTO TABLE lt_path. + DELETE lt_path WHERE table_line IS INITIAL. - do. + DO. lr_node_parent = rr_end_node. - read table mt_json_tree reference into rr_end_node - with key + READ TABLE mt_json_tree REFERENCE INTO rr_end_node + WITH KEY path = lv_cur_path name = lv_cur_name. - if sy-subrc <> 0. " New node, assume it is always object as it has a named child, use touch_array to init array - clear ls_new_node. - if lr_node_parent is not initial. " if has parent + IF sy-subrc <> 0. " New node, assume it is always object as it has a named child, use touch_array to init array + CLEAR ls_new_node. + IF lr_node_parent IS NOT INITIAL. " if has parent lr_node_parent->children = lr_node_parent->children + 1. - if lr_node_parent->type = z2ui5_if_ajson_types=>node_type-array. + IF lr_node_parent->type = z2ui5_if_ajson_types=>node_type-array. ls_new_node-index = lcl_utils=>validate_array_index( iv_path = lv_cur_path iv_index = lv_cur_name ). - endif. - endif. + ENDIF. + ENDIF. ls_new_node-path = lv_cur_path. ls_new_node-name = lv_cur_name. ls_new_node-type = z2ui5_if_ajson_types=>node_type-object. - insert ls_new_node into table mt_json_tree reference into rr_end_node. - endif. + INSERT ls_new_node INTO TABLE mt_json_tree REFERENCE INTO rr_end_node. + ENDIF. lv_cur_path = lv_cur_path && lv_cur_name && '/'. - read table lt_path index sy-index into lv_cur_name. - if sy-subrc <> 0. - exit. " no more segments - endif. - enddo. + READ TABLE lt_path INDEX sy-index INTO lv_cur_name. + IF sy-subrc <> 0. + EXIT. " no more segments + ENDIF. + ENDDO. - endmethod. + ENDMETHOD. - method read_only_watchdog. - if ms_opts-read_only = abap_true. - z2UI5_cx_ajson_error=>raise( 'This json instance is read only' ). - endif. - endmethod. + METHOD read_only_watchdog. + IF ms_opts-read_only = abap_true. + z2ui5_cx_ajson_error=>raise( 'This json instance is read only' ). + ENDIF. + ENDMETHOD. - method z2ui5_if_ajson~array_to_string_table. + METHOD z2ui5_if_ajson~array_to_string_table. - data lv_normalized_path type string. - data lr_node type ref to z2ui5_if_ajson_types=>ty_node. - field-symbols like line of mt_json_tree. + DATA lv_normalized_path TYPE string. + DATA lr_node TYPE REF TO z2ui5_if_ajson_types=>ty_node. + FIELD-SYMBOLS LIKE LINE OF mt_json_tree. lv_normalized_path = lcl_utils=>normalize_path( iv_path ). lr_node = get_item( iv_path ). - if lr_node is initial. - z2UI5_cx_ajson_error=>raise( |Path not found: { iv_path }| ). - endif. - if lr_node->type <> z2ui5_if_ajson_types=>node_type-array. - z2UI5_cx_ajson_error=>raise( |Array expected at: { iv_path }| ). - endif. + IF lr_node IS INITIAL. + z2ui5_cx_ajson_error=>raise( |Path not found: { iv_path }| ). + ENDIF. + IF lr_node->type <> z2ui5_if_ajson_types=>node_type-array. + z2ui5_cx_ajson_error=>raise( |Array expected at: { iv_path }| ). + ENDIF. - loop at mt_json_tree assigning where path = lv_normalized_path. - case -type. - when z2ui5_if_ajson_types=>node_type-number or z2ui5_if_ajson_types=>node_type-string. - append -value to rt_string_table. - when z2ui5_if_ajson_types=>node_type-null. - append '' to rt_string_table. - when z2ui5_if_ajson_types=>node_type-boolean. - data lv_tmp type string. - if -value = 'true'. + LOOP AT mt_json_tree ASSIGNING WHERE path = lv_normalized_path. + CASE -type. + WHEN z2ui5_if_ajson_types=>node_type-number OR z2ui5_if_ajson_types=>node_type-string. + APPEND -value TO rt_string_table. + WHEN z2ui5_if_ajson_types=>node_type-null. + APPEND '' TO rt_string_table. + WHEN z2ui5_if_ajson_types=>node_type-boolean. + DATA lv_tmp TYPE string. + IF -value = 'true'. lv_tmp = abap_true. - else. - clear lv_tmp. - endif. - append lv_tmp to rt_string_table. - when others. - z2UI5_cx_ajson_error=>raise( |Cannot convert [{ -type + ELSE. + CLEAR lv_tmp. + ENDIF. + APPEND lv_tmp TO rt_string_table. + WHEN OTHERS. + z2ui5_cx_ajson_error=>raise( |Cannot convert [{ -type }] to string at [{ -path }{ -name }]| ). - endcase. - endloop. + ENDCASE. + ENDLOOP. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~clear. + METHOD z2ui5_if_ajson~clear. read_only_watchdog( ). - clear mt_json_tree. + CLEAR mt_json_tree. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~clone. + METHOD z2ui5_if_ajson~clone. ri_json = create_from( me ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~delete. + METHOD z2ui5_if_ajson~delete. read_only_watchdog( ). - data ls_split_path type z2ui5_if_ajson_types=>ty_path_name. + DATA ls_split_path TYPE z2ui5_if_ajson_types=>ty_path_name. ls_split_path = lcl_utils=>split_path( iv_path ). delete_subtree( @@ -375,200 +375,200 @@ CLASS Z2UI5_CL_AJSON IMPLEMENTATION. ri_json = me. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~exists. - rv_exists = boolc( get_item( iv_path ) is not initial ). - endmethod. + METHOD z2ui5_if_ajson~exists. + rv_exists = boolc( get_item( iv_path ) IS NOT INITIAL ). + ENDMETHOD. - method z2ui5_if_ajson~filter. + METHOD z2ui5_if_ajson~filter. ri_json = create_from( ii_source_json = me ii_filter = ii_filter ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~format_datetime. + METHOD z2ui5_if_ajson~format_datetime. ms_opts-format_datetime = iv_use_iso. ri_json = me. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~freeze. + METHOD z2ui5_if_ajson~freeze. ms_opts-read_only = abap_true. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~get. + METHOD z2ui5_if_ajson~get. - data lr_item type ref to z2ui5_if_ajson_types=>ty_node. + DATA lr_item TYPE REF TO z2ui5_if_ajson_types=>ty_node. lr_item = get_item( iv_path ). - if lr_item is not initial. + IF lr_item IS NOT INITIAL. rv_value = lr_item->value. - endif. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~get_boolean. + METHOD z2ui5_if_ajson~get_boolean. - data lr_item type ref to z2ui5_if_ajson_types=>ty_node. + DATA lr_item TYPE REF TO z2ui5_if_ajson_types=>ty_node. lr_item = get_item( iv_path ). - if lr_item is initial or lr_item->type = z2ui5_if_ajson_types=>node_type-null. - return. - elseif lr_item->type = z2ui5_if_ajson_types=>node_type-boolean. + IF lr_item IS INITIAL OR lr_item->type = z2ui5_if_ajson_types=>node_type-null. + RETURN. + ELSEIF lr_item->type = z2ui5_if_ajson_types=>node_type-boolean. rv_value = boolc( lr_item->value = 'true' ). - elseif lr_item->value is not initial. + ELSEIF lr_item->value IS NOT INITIAL. rv_value = abap_true. - endif. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~get_date. + METHOD z2ui5_if_ajson~get_date. - data lr_item type ref to z2ui5_if_ajson_types=>ty_node. - data lv_y type c length 4. - data lv_m type c length 2. - data lv_d type c length 2. + DATA lr_item TYPE REF TO z2ui5_if_ajson_types=>ty_node. + DATA lv_y TYPE c LENGTH 4. + DATA lv_m TYPE c LENGTH 2. + DATA lv_d TYPE c LENGTH 2. lr_item = get_item( iv_path ). - if lr_item is not initial and lr_item->type = z2ui5_if_ajson_types=>node_type-string. - find first occurrence of regex '^(\d{4})-(\d{2})-(\d{2})(T|$)' "#EC NOTEXT - in lr_item->value - submatches lv_y lv_m lv_d. - concatenate lv_y lv_m lv_d into rv_value. - endif. + IF lr_item IS NOT INITIAL AND lr_item->type = z2ui5_if_ajson_types=>node_type-string. + FIND FIRST OCCURRENCE OF REGEX '^(\d{4})-(\d{2})-(\d{2})(T|$)' + IN lr_item->value + SUBMATCHES lv_y lv_m lv_d. + CONCATENATE lv_y lv_m lv_d INTO rv_value. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~get_integer. + METHOD z2ui5_if_ajson~get_integer. - data lr_item type ref to z2ui5_if_ajson_types=>ty_node. + DATA lr_item TYPE REF TO z2ui5_if_ajson_types=>ty_node. lr_item = get_item( iv_path ). - if lr_item is not initial and lr_item->type = z2ui5_if_ajson_types=>node_type-number. + IF lr_item IS NOT INITIAL AND lr_item->type = z2ui5_if_ajson_types=>node_type-number. rv_value = lr_item->value. - endif. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~get_node_type. + METHOD z2ui5_if_ajson~get_node_type. - data lr_item type ref to z2ui5_if_ajson_types=>ty_node. + DATA lr_item TYPE REF TO z2ui5_if_ajson_types=>ty_node. lr_item = get_item( iv_path ). - if lr_item is not initial. + IF lr_item IS NOT INITIAL. rv_node_type = lr_item->type. - endif. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~get_number. + METHOD z2ui5_if_ajson~get_number. - data lr_item type ref to z2ui5_if_ajson_types=>ty_node. + DATA lr_item TYPE REF TO z2ui5_if_ajson_types=>ty_node. lr_item = get_item( iv_path ). - if lr_item is not initial and lr_item->type = z2ui5_if_ajson_types=>node_type-number. + IF lr_item IS NOT INITIAL AND lr_item->type = z2ui5_if_ajson_types=>node_type-number. rv_value = lr_item->value. - endif. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~get_string. + METHOD z2ui5_if_ajson~get_string. - data lr_item type ref to z2ui5_if_ajson_types=>ty_node. + DATA lr_item TYPE REF TO z2ui5_if_ajson_types=>ty_node. lr_item = get_item( iv_path ). - if lr_item is not initial and lr_item->type <> z2ui5_if_ajson_types=>node_type-null. + IF lr_item IS NOT INITIAL AND lr_item->type <> z2ui5_if_ajson_types=>node_type-null. rv_value = lr_item->value. - endif. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~get_timestamp. + METHOD z2ui5_if_ajson~get_timestamp. - data lo_to_abap type ref to lcl_json_to_abap. - data lr_item type ref to z2ui5_if_ajson_types=>ty_node. + DATA lo_to_abap TYPE REF TO lcl_json_to_abap. + DATA lr_item TYPE REF TO z2ui5_if_ajson_types=>ty_node. lr_item = get_item( iv_path ). - if lr_item is initial. - return. - endif. + IF lr_item IS INITIAL. + RETURN. + ENDIF. - create object lo_to_abap. + CREATE OBJECT lo_to_abap. - try. - rv_value = lo_to_abap->to_timestamp( lr_item->value ). - catch z2UI5_cx_ajson_error. - return. - endtry. + TRY. + rv_value = lo_to_abap->to_timestamp( lr_item->value ). + CATCH z2ui5_cx_ajson_error. + RETURN. + ENDTRY. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~is_empty. + METHOD z2ui5_if_ajson~is_empty. rv_yes = boolc( lines( mt_json_tree ) = 0 ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~keep_item_order. + METHOD z2ui5_if_ajson~keep_item_order. ms_opts-keep_item_order = abap_true. ri_json = me. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~map. + METHOD z2ui5_if_ajson~map. ri_json = create_from( ii_source_json = me ii_mapper = ii_mapper ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~members. + METHOD z2ui5_if_ajson~members. - data lv_normalized_path type string. - field-symbols like line of mt_json_tree. + DATA lv_normalized_path TYPE string. + FIELD-SYMBOLS LIKE LINE OF mt_json_tree. lv_normalized_path = lcl_utils=>normalize_path( iv_path ). - loop at mt_json_tree assigning where path = lv_normalized_path. - append -name to rt_members. - endloop. + LOOP AT mt_json_tree ASSIGNING WHERE path = lv_normalized_path. + APPEND -name TO rt_members. + ENDLOOP. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~opts. + METHOD z2ui5_if_ajson~opts. rs_opts = ms_opts. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~push. + METHOD z2ui5_if_ajson~push. - data lr_parent type ref to z2ui5_if_ajson_types=>ty_node. - data lr_new_node type ref to z2ui5_if_ajson_types=>ty_node. + DATA lr_parent TYPE REF TO z2ui5_if_ajson_types=>ty_node. + DATA lr_new_node TYPE REF TO z2ui5_if_ajson_types=>ty_node. read_only_watchdog( ). lr_parent = get_item( iv_path ). - if lr_parent is initial. - z2UI5_cx_ajson_error=>raise( |Path [{ iv_path }] does not exist| ). - endif. + IF lr_parent IS INITIAL. + z2ui5_cx_ajson_error=>raise( |Path [{ iv_path }] does not exist| ). + ENDIF. - if lr_parent->type <> z2ui5_if_ajson_types=>node_type-array. - z2UI5_cx_ajson_error=>raise( |Path [{ iv_path }] is not array| ). - endif. + IF lr_parent->type <> z2ui5_if_ajson_types=>node_type-array. + z2ui5_cx_ajson_error=>raise( |Path [{ iv_path }] is not array| ). + ENDIF. - data lt_new_nodes type z2ui5_if_ajson_types=>ty_nodes_tt. - data ls_new_path type z2ui5_if_ajson_types=>ty_path_name. - data lv_new_index type i. + DATA lt_new_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt. + DATA ls_new_path TYPE z2ui5_if_ajson_types=>ty_path_name. + DATA lv_new_index TYPE i. lv_new_index = lr_parent->children + 1. ls_new_path-path = lcl_utils=>normalize_path( iv_path ). @@ -578,62 +578,62 @@ CLASS Z2UI5_CL_AJSON IMPLEMENTATION. is_opts = ms_opts iv_data = iv_val is_prefix = ls_new_path ). - read table lt_new_nodes index 1 reference into lr_new_node. " assume first record is the array item - not ideal ! - assert sy-subrc = 0. + READ TABLE lt_new_nodes INDEX 1 REFERENCE INTO lr_new_node. " assume first record is the array item - not ideal ! + ASSERT sy-subrc = 0. lr_new_node->index = lv_new_index. " update data lr_parent->children = lv_new_index. - insert lines of lt_new_nodes into table mt_json_tree. + INSERT LINES OF lt_new_nodes INTO TABLE mt_json_tree. ri_json = me. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~set. + METHOD z2ui5_if_ajson~set. - data ls_split_path type z2ui5_if_ajson_types=>ty_path_name. - data lr_parent type ref to z2ui5_if_ajson_types=>ty_node. - data ls_deleted_node type z2ui5_if_ajson_types=>ty_node. - data lv_item_order type z2ui5_if_ajson_types=>ty_node-order. + DATA ls_split_path TYPE z2ui5_if_ajson_types=>ty_path_name. + DATA lr_parent TYPE REF TO z2ui5_if_ajson_types=>ty_node. + DATA ls_deleted_node TYPE z2ui5_if_ajson_types=>ty_node. + DATA lv_item_order TYPE z2ui5_if_ajson_types=>ty_node-order. read_only_watchdog( ). ri_json = me. - if iv_val is initial and iv_ignore_empty = abap_true and iv_node_type is initial. - return. " nothing to assign - endif. + IF iv_val IS INITIAL AND iv_ignore_empty = abap_true AND iv_node_type IS INITIAL. + RETURN. " nothing to assign + ENDIF. - if iv_node_type is not initial - and iv_node_type <> z2ui5_if_ajson_types=>node_type-boolean and iv_node_type <> z2ui5_if_ajson_types=>node_type-null - and iv_node_type <> z2ui5_if_ajson_types=>node_type-number and iv_node_type <> z2ui5_if_ajson_types=>node_type-string. - z2UI5_cx_ajson_error=>raise( |Unexpected type { iv_node_type }| ). - endif. + IF iv_node_type IS NOT INITIAL + AND iv_node_type <> z2ui5_if_ajson_types=>node_type-boolean AND iv_node_type <> z2ui5_if_ajson_types=>node_type-null + AND iv_node_type <> z2ui5_if_ajson_types=>node_type-number AND iv_node_type <> z2ui5_if_ajson_types=>node_type-string. + z2ui5_cx_ajson_error=>raise( |Unexpected type { iv_node_type }| ). + ENDIF. ls_split_path = lcl_utils=>split_path( iv_path ). - if ls_split_path is initial. " Assign root, exceptional processing - if iv_node_type is not initial. + IF ls_split_path IS INITIAL. " Assign root, exceptional processing + IF iv_node_type IS NOT INITIAL. mt_json_tree = lcl_abap_to_json=>insert_with_type( is_opts = ms_opts iv_data = iv_val iv_type = iv_node_type is_prefix = ls_split_path ii_custom_mapping = mi_custom_mapping ). - else. + ELSE. mt_json_tree = lcl_abap_to_json=>convert( is_opts = ms_opts iv_data = iv_val is_prefix = ls_split_path ii_custom_mapping = mi_custom_mapping ). - endif. - return. - endif. + ENDIF. + RETURN. + ENDIF. " Ensure whole path exists lr_parent = prove_path_exists( ls_split_path-path ). - assert lr_parent is not initial. + ASSERT lr_parent IS NOT INITIAL. " delete if exists with subtree ls_deleted_node = delete_subtree( @@ -643,19 +643,19 @@ CLASS Z2UI5_CL_AJSON IMPLEMENTATION. lv_item_order = ls_deleted_node-order. " convert to json - data lt_new_nodes type z2ui5_if_ajson_types=>ty_nodes_tt. - data lv_array_index type i. + DATA lt_new_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt. + DATA lv_array_index TYPE i. - if lr_parent->type = z2ui5_if_ajson_types=>node_type-array. + IF lr_parent->type = z2ui5_if_ajson_types=>node_type-array. lv_array_index = lcl_utils=>validate_array_index( iv_path = ls_split_path-path iv_index = ls_split_path-name ). - elseif lr_parent->type = z2ui5_if_ajson_types=>node_type-object - and lv_item_order = 0 and ms_opts-keep_item_order = abap_true. + ELSEIF lr_parent->type = z2ui5_if_ajson_types=>node_type-object + AND lv_item_order = 0 AND ms_opts-keep_item_order = abap_true. lv_item_order = lr_parent->children + 1. - endif. + ENDIF. - if iv_node_type is not initial. + IF iv_node_type IS NOT INITIAL. lt_new_nodes = lcl_abap_to_json=>insert_with_type( is_opts = ms_opts iv_item_order = lv_item_order @@ -664,7 +664,7 @@ CLASS Z2UI5_CL_AJSON IMPLEMENTATION. iv_array_index = lv_array_index is_prefix = ls_split_path ii_custom_mapping = mi_custom_mapping ). - else. + ELSE. lt_new_nodes = lcl_abap_to_json=>convert( is_opts = ms_opts iv_item_order = lv_item_order @@ -672,108 +672,108 @@ CLASS Z2UI5_CL_AJSON IMPLEMENTATION. iv_array_index = lv_array_index is_prefix = ls_split_path ii_custom_mapping = mi_custom_mapping ). - endif. + ENDIF. " update nodes - if lines( lt_new_nodes ) > 0. + IF lines( lt_new_nodes ) > 0. lr_parent->children = lr_parent->children + 1. - insert lines of lt_new_nodes into table mt_json_tree. - endif. + INSERT LINES OF lt_new_nodes INTO TABLE mt_json_tree. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~setx. + METHOD z2ui5_if_ajson~setx. - data lv_path type string. - data lv_val type string. - data lv_int type i. - data lv_dec type decfloat34. - data lv_last type i. + DATA lv_path TYPE string. + DATA lv_val TYPE string. + DATA lv_int TYPE i. + DATA lv_dec TYPE decfloat34. + DATA lv_last TYPE i. - if iv_param is initial. + IF iv_param IS INITIAL. ri_json = me. - return. - endif. + RETURN. + ENDIF. - split iv_param at ':' into lv_path lv_val. - condense lv_path. - condense lv_val. + SPLIT iv_param AT ':' INTO lv_path lv_val. + CONDENSE lv_path. + CONDENSE lv_val. - if lv_val is initial. + IF lv_val IS INITIAL. ri_json = me. - return. " Hmm ? or empty string ? or null ? - endif. + RETURN. " Hmm ? or empty string ? or null ? + ENDIF. - if go_float_regex is not bound. - create object go_float_regex exporting pattern = '^([1-9][0-9]*|0)\.[0-9]+$'. + IF go_float_regex IS NOT BOUND. + CREATE OBJECT go_float_regex EXPORTING pattern = '^([1-9][0-9]*|0)\.[0-9]+$'. " expects fractional, because ints are detected separately - endif. + ENDIF. - if lv_val = 'null'. + IF lv_val = 'null'. z2ui5_if_ajson~set_null( lv_path ). - elseif lv_val = 'true'. + ELSEIF lv_val = 'true'. z2ui5_if_ajson~set_boolean( iv_path = lv_path iv_val = abap_true ). - elseif lv_val = 'false'. + ELSEIF lv_val = 'false'. z2ui5_if_ajson~set_boolean( iv_path = lv_path iv_val = abap_false ). - elseif lv_val co '0123456789'. + ELSEIF lv_val CO '0123456789'. lv_int = lv_val. z2ui5_if_ajson~set_integer( iv_path = lv_path iv_val = lv_int ). - elseif lv_val co '0123456789.' and go_float_regex->create_matcher( text = lv_val )->match( ) = abap_true. + ELSEIF lv_val CO '0123456789.' AND go_float_regex->create_matcher( text = lv_val )->match( ) = abap_true. lv_dec = lv_val. z2ui5_if_ajson~set( iv_path = lv_path iv_val = lv_dec ). - elseif lv_val+0(1) = '{' or lv_val+0(1) = '['. + ELSEIF lv_val+0(1) = '{' OR lv_val+0(1) = '['. "Expect object/array, but no further checks, parser will catch errors z2ui5_if_ajson~set( iv_path = lv_path iv_val = parse( iv_json = lv_val iv_keep_item_order = ms_opts-keep_item_order ) ). - else. " string + ELSE. " string lv_last = strlen( lv_val ) - 1. - if lv_val+0(1) = '"' and lv_val+lv_last(1) = '"'. + IF lv_val+0(1) = '"' AND lv_val+lv_last(1) = '"'. lv_val = substring( val = lv_val off = 1 len = lv_last - 1 ). - endif. + ENDIF. z2ui5_if_ajson~set_string( iv_path = lv_path iv_val = lv_val ). - endif. + ENDIF. ri_json = me. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~set_boolean. + METHOD z2ui5_if_ajson~set_boolean. ri_json = me. - data lv_bool type abap_bool. - lv_bool = boolc( iv_val is not initial ). + DATA lv_bool TYPE abap_bool. + lv_bool = boolc( iv_val IS NOT INITIAL ). z2ui5_if_ajson~set( iv_ignore_empty = abap_false iv_path = iv_path iv_val = lv_bool ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~set_date. + METHOD z2ui5_if_ajson~set_date. ri_json = me. - data lv_val type string. + DATA lv_val TYPE string. lv_val = lcl_abap_to_json=>format_date( iv_val ). z2ui5_if_ajson~set( @@ -781,10 +781,10 @@ CLASS Z2UI5_CL_AJSON IMPLEMENTATION. iv_path = iv_path iv_val = lv_val ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~set_integer. + METHOD z2ui5_if_ajson~set_integer. ri_json = me. @@ -793,41 +793,41 @@ CLASS Z2UI5_CL_AJSON IMPLEMENTATION. iv_path = iv_path iv_val = iv_val ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~set_null. + METHOD z2ui5_if_ajson~set_null. ri_json = me. - data lv_null_ref type ref to data. + DATA lv_null_ref TYPE REF TO data. z2ui5_if_ajson~set( iv_ignore_empty = abap_false iv_path = iv_path iv_val = lv_null_ref ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~set_string. + METHOD z2ui5_if_ajson~set_string. ri_json = me. - data lv_val type string. + DATA lv_val TYPE string. lv_val = iv_val. z2ui5_if_ajson~set( iv_ignore_empty = abap_false iv_path = iv_path iv_val = lv_val ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~set_timestamp. + METHOD z2ui5_if_ajson~set_timestamp. ri_json = me. - data lv_timestamp_iso type string. + DATA lv_timestamp_iso TYPE string. lv_timestamp_iso = lcl_abap_to_json=>format_timestamp( iv_val ). z2ui5_if_ajson~set( @@ -835,87 +835,88 @@ CLASS Z2UI5_CL_AJSON IMPLEMENTATION. iv_path = iv_path iv_val = lv_timestamp_iso ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~slice. + METHOD z2ui5_if_ajson~slice. - data lo_section type ref to z2ui5_cl_ajson. - data ls_item like line of mt_json_tree. - data lv_normalized_path type string. - data ls_path_parts type z2ui5_if_ajson_types=>ty_path_name. - data lv_path_len type i. - data lv_path_pattern type string. + DATA lo_section TYPE REF TO z2ui5_cl_ajson. + DATA ls_item LIKE LINE OF mt_json_tree. + DATA lv_normalized_path TYPE string. + DATA ls_path_parts TYPE z2ui5_if_ajson_types=>ty_path_name. + DATA lv_path_len TYPE i. + DATA lv_path_pattern TYPE string. - create object lo_section. + CREATE OBJECT lo_section. lv_normalized_path = lcl_utils=>normalize_path( iv_path ). lv_path_len = strlen( lv_normalized_path ). ls_path_parts = lcl_utils=>split_path( lv_normalized_path ). - read table mt_json_tree into ls_item - with key path = ls_path_parts-path name = ls_path_parts-name. - if sy-subrc <> 0. - return. - endif. + READ TABLE mt_json_tree INTO ls_item + WITH KEY path = ls_path_parts-path name = ls_path_parts-name. + IF sy-subrc <> 0. + RETURN. + ENDIF. - clear: ls_item-path, ls_item-name, ls_item-order. " this becomes a new root - insert ls_item into table lo_section->mt_json_tree. + CLEAR: ls_item-path, ls_item-name, ls_item-order. " this becomes a new root + INSERT ls_item INTO TABLE lo_section->mt_json_tree. lv_path_pattern = lv_normalized_path && `*`. - loop at mt_json_tree into ls_item where path cp lv_path_pattern. + LOOP AT mt_json_tree INTO ls_item WHERE path CP lv_path_pattern. - ls_item-path = substring( val = ls_item-path off = lv_path_len - 1 ). " less closing '/' - insert ls_item into table lo_section->mt_json_tree. + ls_item-path = substring( val = ls_item-path + off = lv_path_len - 1 ). " less closing '/' + INSERT ls_item INTO TABLE lo_section->mt_json_tree. - endloop. + ENDLOOP. ri_json = lo_section. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~stringify. + METHOD z2ui5_if_ajson~stringify. rv_json = lcl_json_serializer=>stringify( it_json_tree = mt_json_tree iv_keep_item_order = ms_opts-keep_item_order iv_indent = iv_indent ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~touch_array. + METHOD z2ui5_if_ajson~touch_array. - data lr_node type ref to z2ui5_if_ajson_types=>ty_node. - data ls_deleted_node type z2ui5_if_ajson_types=>ty_node. - data ls_new_node like line of mt_json_tree. - data ls_split_path type z2ui5_if_ajson_types=>ty_path_name. + DATA lr_node TYPE REF TO z2ui5_if_ajson_types=>ty_node. + DATA ls_deleted_node TYPE z2ui5_if_ajson_types=>ty_node. + DATA ls_new_node LIKE LINE OF mt_json_tree. + DATA ls_split_path TYPE z2ui5_if_ajson_types=>ty_path_name. read_only_watchdog( ). ls_split_path = lcl_utils=>split_path( iv_path ). - if ls_split_path is initial. " Assign root, exceptional processing + IF ls_split_path IS INITIAL. " Assign root, exceptional processing ls_new_node-path = ls_split_path-path. ls_new_node-name = ls_split_path-name. ls_new_node-type = z2ui5_if_ajson_types=>node_type-array. - insert ls_new_node into table mt_json_tree. - return. - endif. + INSERT ls_new_node INTO TABLE mt_json_tree. + RETURN. + ENDIF. - if iv_clear = abap_true. + IF iv_clear = abap_true. ls_deleted_node = delete_subtree( iv_path = ls_split_path-path iv_name = ls_split_path-name ). - else. + ELSE. lr_node = get_item( iv_path ). - endif. + ENDIF. - if lr_node is initial. " Or node was cleared + IF lr_node IS INITIAL. " Or node was cleared - data lr_parent type ref to z2ui5_if_ajson_types=>ty_node. + DATA lr_parent TYPE REF TO z2ui5_if_ajson_types=>ty_node. lr_parent = prove_path_exists( ls_split_path-path ). - assert lr_parent is not initial. + ASSERT lr_parent IS NOT INITIAL. lr_parent->children = lr_parent->children + 1. @@ -923,42 +924,46 @@ CLASS Z2UI5_CL_AJSON IMPLEMENTATION. ls_new_node-name = ls_split_path-name. ls_new_node-type = z2ui5_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. - endif. + 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. + INSERT ls_new_node INTO TABLE mt_json_tree. - elseif lr_node->type <> z2ui5_if_ajson_types=>node_type-array. - z2UI5_cx_ajson_error=>raise( |Path [{ iv_path }] already used and is not array| ). - endif. + ELSEIF lr_node->type <> z2ui5_if_ajson_types=>node_type-array. + z2ui5_cx_ajson_error=>raise( |Path [{ iv_path }] already used and is not array| ). + ENDIF. ri_json = me. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~to_abap. + METHOD z2ui5_if_ajson~to_abap. - data lo_to_abap type ref to lcl_json_to_abap. + DATA lo_to_abap TYPE REF TO lcl_json_to_abap. - clear ev_container. - create object lo_to_abap - exporting - iv_corresponding = boolc( iv_corresponding = abap_true or ms_opts-to_abap_corresponding_only = abap_true ) + CLEAR ev_container. + CREATE OBJECT lo_to_abap + EXPORTING + iv_corresponding = boolc( iv_corresponding = abap_true OR ms_opts-to_abap_corresponding_only = abap_true ) ii_custom_mapping = mi_custom_mapping. lo_to_abap->to_abap( - exporting + EXPORTING it_nodes = z2ui5_if_ajson~mt_json_tree - changing + CHANGING c_container = ev_container ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson~to_abap_corresponding_only. + METHOD z2ui5_if_ajson~to_abap_corresponding_only. ms_opts-to_abap_corresponding_only = iv_enable. ri_json = me. - endmethod. + ENDMETHOD. ENDCLASS. diff --git a/src/01/00/01/z2ui5_cl_ajson.clas.locals_imp.abap b/src/01/00/01/z2ui5_cl_ajson.clas.locals_imp.abap index 6e3ae68d..8af256ad 100644 --- a/src/01/00/01/z2ui5_cl_ajson.clas.locals_imp.abap +++ b/src/01/00/01/z2ui5_cl_ajson.clas.locals_imp.abap @@ -59,25 +59,25 @@ CLASS lcl_utils DEFINITION FINAL. CLASS-METHODS normalize_path IMPORTING - iv_path TYPE string + iv_path TYPE string RETURNING VALUE(rv_path) TYPE string. CLASS-METHODS split_path IMPORTING - iv_path TYPE string + iv_path TYPE string RETURNING VALUE(rv_path_name) TYPE z2ui5_if_ajson_types=>ty_path_name. CLASS-METHODS validate_array_index IMPORTING - iv_path TYPE string - iv_index TYPE string + iv_path TYPE string + iv_index TYPE string RETURNING VALUE(rv_index) TYPE i RAISING - z2UI5_cx_ajson_error. + z2ui5_cx_ajson_error. CLASS-METHODS string_to_xstring_utf8 IMPORTING - iv_str TYPE string + iv_str TYPE string RETURNING VALUE(rv_xstr) TYPE xstring. @@ -94,24 +94,24 @@ CLASS lcl_utils IMPLEMENTATION. TRY. CALL METHOD ('CL_ABAP_CONV_CODEPAGE')=>create_out - RECEIVING - instance = lo_conv. + RECEIVING + instance = lo_conv. CALL METHOD lo_conv->('IF_ABAP_CONV_OUT~CONVERT') - EXPORTING - source = iv_str - RECEIVING - result = rv_xstr. + EXPORTING + source = iv_str + RECEIVING + result = rv_xstr. CATCH cx_sy_dyn_call_illegal_class. CALL METHOD (lv_out_ce)=>create - EXPORTING - encoding = 'UTF-8' - RECEIVING - conv = lo_conv. + EXPORTING + encoding = 'UTF-8' + RECEIVING + conv = lo_conv. CALL METHOD lo_conv->('CONVERT') - EXPORTING - data = iv_str - IMPORTING - buffer = rv_xstr. + EXPORTING + data = iv_str + IMPORTING + buffer = rv_xstr. ENDTRY. ENDMETHOD. @@ -137,7 +137,8 @@ CLASS lcl_utils IMPLEMENTATION. IF rv_path+0(1) <> '/'. rv_path = '/' && rv_path. ENDIF. - IF substring( val = rv_path off = strlen( rv_path ) - 1 ) <> '/'. + IF substring( val = rv_path + off = strlen( rv_path ) - 1 ) <> '/'. rv_path = rv_path && '/'. ENDIF. @@ -154,18 +155,24 @@ CLASS lcl_utils IMPLEMENTATION. RETURN. " empty path is the alias for root item = '' + '' ENDIF. - IF substring( val = iv_path off = lv_len - 1 ) = '/'. + IF substring( val = iv_path + off = lv_len - 1 ) = '/'. lv_trim_slash = 1. " ignore last '/' ENDIF. - lv_offs = find( val = reverse( iv_path ) sub = '/' off = lv_trim_slash ). + lv_offs = find( val = reverse( iv_path ) + sub = '/' + off = lv_trim_slash ). IF lv_offs = -1. lv_offs = lv_len. " treat whole string as the 'name' part ENDIF. lv_offs = lv_len - lv_offs. - rv_path_name-path = normalize_path( substring( val = iv_path len = lv_offs ) ). - rv_path_name-name = substring( val = iv_path off = lv_offs len = lv_len - lv_offs - lv_trim_slash ). + rv_path_name-path = normalize_path( substring( val = iv_path + len = lv_offs ) ). + rv_path_name-name = substring( val = iv_path + off = lv_offs + len = lv_len - lv_offs - lv_trim_slash ). ENDMETHOD. @@ -181,8 +188,8 @@ CLASS lcl_json_parser DEFINITION FINAL. METHODS parse IMPORTING - iv_json TYPE string - iv_keep_item_order TYPE abap_bool DEFAULT abap_false + iv_json TYPE string + iv_keep_item_order TYPE abap_bool DEFAULT abap_false RETURNING VALUE(rt_json_tree) TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING @@ -205,7 +212,7 @@ CLASS lcl_json_parser DEFINITION FINAL. METHODS _parse IMPORTING - iv_json TYPE string + iv_json TYPE string RETURNING VALUE(rt_json_tree) TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING @@ -230,21 +237,21 @@ CLASS lcl_json_parser IMPLEMENTATION. mv_keep_item_order = iv_keep_item_order. TRY. - " TODO sane JSON check: - " JSON can be true,false,null,(-)digits - " or start from " or from { + " TODO sane JSON check: + " JSON can be true,false,null,(-)digits + " or start from " or from { rt_json_tree = _parse( iv_json ). CATCH cx_sxml_parse_error INTO lx_sxml_parse. lv_location = _get_location( - iv_json = iv_json - iv_offset = lx_sxml_parse->xml_offset ). + iv_json = iv_json + iv_offset = lx_sxml_parse->xml_offset ). z2ui5_cx_ajson_error=>raise( - iv_msg = |Json parsing error (SXML): { lx_sxml_parse->get_text( ) }| - iv_location = lv_location ). + iv_msg = |Json parsing error (SXML): { lx_sxml_parse->get_text( ) }| + iv_location = lv_location ). CATCH cx_dynamic_check INTO lx_sxml. " cx_sxml_error z2ui5_cx_ajson_error=>raise( - iv_msg = |Json parsing error (SXML): { lx_sxml->get_text( ) }| - iv_location = '@PARSER' ). + iv_msg = |Json parsing error (SXML): { lx_sxml->get_text( ) }| + iv_location = '@PARSER' ). ENDTRY. ENDMETHOD. @@ -253,7 +260,7 @@ CLASS lcl_json_parser IMPLEMENTATION. DATA lv_json TYPE string. DATA lv_offset TYPE i. - DATA lt_text TYPE STANDARD TABLE OF string. + DATA lt_text TYPE TABLE OF string. DATA lv_text TYPE string. DATA lv_line TYPE i. DATA lv_pos TYPE i. @@ -361,7 +368,8 @@ CLASS lcl_json_parser IMPLEMENTATION. ENDIF. " remove last path component - mv_stack_path = substring( val = mv_stack_path len = find( val = mv_stack_path sub = '/' occ = -2 ) + 1 ). + mv_stack_path = substring( val = mv_stack_path + len = find( val = mv_stack_path sub = '/' occ = -2 ) + 1 ). WHEN if_sxml_node=>co_nt_value. DATA lo_value TYPE REF TO if_sxml_value_node. lo_value ?= lo_node. @@ -398,9 +406,9 @@ CLASS lcl_json_serializer DEFINITION FINAL CREATE PRIVATE. CLASS-METHODS stringify IMPORTING - it_json_tree TYPE z2ui5_if_ajson_types=>ty_nodes_ts - iv_indent TYPE i DEFAULT 0 - iv_keep_item_order TYPE abap_bool DEFAULT abap_false + it_json_tree TYPE z2ui5_if_ajson_types=>ty_nodes_ts + iv_indent TYPE i DEFAULT 0 + iv_keep_item_order TYPE abap_bool DEFAULT abap_false RETURNING VALUE(rv_json_string) TYPE string RAISING @@ -420,7 +428,7 @@ CLASS lcl_json_serializer DEFINITION FINAL CREATE PRIVATE. CLASS-METHODS escape_string IMPORTING - iv_unescaped TYPE string + iv_unescaped TYPE string RETURNING VALUE(rv_escaped) TYPE string. @@ -439,7 +447,7 @@ CLASS lcl_json_serializer DEFINITION FINAL CREATE PRIVATE. METHODS stringify_set IMPORTING iv_parent_path TYPE string - iv_array TYPE abap_bool + iv_array TYPE abap_bool RAISING z2ui5_cx_ajson_error. @@ -485,7 +493,8 @@ CLASS lcl_json_serializer IMPLEMENTATION. DATA lv_indent_prefix TYPE string. IF mv_indent_step > 0. - lv_indent_prefix = repeat( val = ` ` occ = mv_indent_step * mv_level ). + lv_indent_prefix = repeat( val = ` ` + occ = mv_indent_step * mv_level ). lv_item = lv_indent_prefix. ENDIF. @@ -641,7 +650,7 @@ CLASS lcl_json_to_abap DEFINITION FINAL. METHODS to_abap IMPORTING - it_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_ts + it_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_ts CHANGING c_container TYPE any RAISING @@ -689,16 +698,16 @@ CLASS lcl_json_to_abap DEFINITION FINAL. METHODS any_to_abap IMPORTING - iv_path TYPE string - is_parent_type TYPE ty_type_cache OPTIONAL + iv_path TYPE string + is_parent_type TYPE ty_type_cache OPTIONAL i_container_ref TYPE REF TO data RAISING z2ui5_cx_ajson_error. METHODS value_to_abap IMPORTING - is_node TYPE z2ui5_if_ajson_types=>ty_node - is_node_type TYPE ty_type_cache + is_node TYPE z2ui5_if_ajson_types=>ty_node + is_node_type TYPE ty_type_cache i_container_ref TYPE REF TO data RAISING z2ui5_cx_ajson_error @@ -706,9 +715,9 @@ CLASS lcl_json_to_abap DEFINITION FINAL. METHODS get_node_type IMPORTING - is_node TYPE z2ui5_if_ajson_types=>ty_node OPTIONAL " Empty for root - is_parent_type TYPE ty_type_cache OPTIONAL - i_container_ref TYPE REF TO data OPTIONAL + is_node TYPE z2ui5_if_ajson_types=>ty_node OPTIONAL " Empty for root + is_parent_type TYPE ty_type_cache OPTIONAL + i_container_ref TYPE REF TO data OPTIONAL RETURNING VALUE(rs_node_type) TYPE ty_type_cache RAISING @@ -852,16 +861,16 @@ CLASS lcl_json_to_abap IMPLEMENTATION. TRY. - " array_index because stringified index goes in wrong order [1, 10, 2 ...] + " array_index because stringified index goes in wrong order [1, 10, 2 ...] LOOP AT mr_nodes->* ASSIGNING USING KEY array_index WHERE path = iv_path. - " Get or create type cache record + " Get or create type cache record IF is_parent_type-type_kind <> lif_kind=>table OR ls_node_type-type_kind IS INITIAL. - " table records are the same, no need to refetch twice + " table records are the same, no need to refetch twice ls_node_type = get_node_type( - is_node = - is_parent_type = is_parent_type ). + is_node = + is_parent_type = is_parent_type ). IF mv_corresponding = abap_true AND ls_node_type IS INITIAL. CONTINUE. @@ -869,24 +878,26 @@ CLASS lcl_json_to_abap IMPLEMENTATION. ENDIF. - " Validate node type + " Validate node type IF ls_node_type-type_kind = lif_kind=>data_ref OR - ls_node_type-type_kind = lif_kind=>object_ref. - " TODO maybe in future + ls_node_type-type_kind = lif_kind=>object_ref. + " TODO maybe in future z2ui5_cx_ajson_error=>raise( 'Cannot assign to ref' ). ENDIF. - " Find target field reference + " Find target field reference CASE is_parent_type-type_kind. WHEN lif_kind=>table. IF NOT ls_node_type-target_field_name CO '0123456789'. - " Does not affect anything actually but for integrity + " Does not affect anything actually but for integrity z2ui5_cx_ajson_error=>raise( 'Need index to access tables' ). ENDIF. 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 REFERENCE INTO lr_target_field. ASSERT sy-subrc = 0. + ELSE. + CLEAR . ENDIF. WHEN lif_kind=>struct_flat OR lif_kind=>struct_deep. @@ -902,32 +913,32 @@ CLASS lcl_json_to_abap IMPLEMENTATION. z2ui5_cx_ajson_error=>raise( 'Unexpected parent type' ). ENDCASE. - " Process value assignment + " Process value assignment CASE -type. WHEN z2ui5_if_ajson_types=>node_type-object. IF ls_node_type-type_kind <> lif_kind=>struct_flat AND - ls_node_type-type_kind <> lif_kind=>struct_deep. + ls_node_type-type_kind <> lif_kind=>struct_deep. z2ui5_cx_ajson_error=>raise( 'Expected structure' ). ENDIF. any_to_abap( - iv_path = -path && -name && '/' - is_parent_type = ls_node_type - i_container_ref = lr_target_field ). + iv_path = -path && -name && '/' + is_parent_type = ls_node_type + i_container_ref = lr_target_field ). WHEN z2ui5_if_ajson_types=>node_type-array. IF NOT ls_node_type-type_kind = lif_kind=>table. z2ui5_cx_ajson_error=>raise( 'Expected table' ). ENDIF. any_to_abap( - iv_path = -path && -name && '/' - is_parent_type = ls_node_type - i_container_ref = lr_target_field ). + iv_path = -path && -name && '/' + is_parent_type = ls_node_type + i_container_ref = lr_target_field ). WHEN OTHERS. value_to_abap( - is_node = - is_node_type = ls_node_type - i_container_ref = lr_target_field ). + is_node = + is_node_type = ls_node_type + i_container_ref = lr_target_field ). ENDCASE. IF is_parent_type-tab_item_buf IS BOUND. " Indirect hint that table was sorted/hashed, see get_node_type. @@ -950,12 +961,12 @@ CLASS lcl_json_to_abap IMPLEMENTATION. RAISE EXCEPTION lx_ajson. CATCH cx_sy_conversion_no_number. z2ui5_cx_ajson_error=>raise( - iv_msg = 'Source is not a number' - iv_location = -path && -name ). + iv_msg = 'Source is not a number' + iv_location = -path && -name ). CATCH cx_root INTO lx_root. z2ui5_cx_ajson_error=>raise( - iv_msg = lx_root->get_text( ) - iv_location = -path && -name ). + iv_msg = lx_root->get_text( ) + iv_location = -path && -name ). ENDTRY. ENDMETHOD. @@ -1011,7 +1022,7 @@ CLASS lcl_json_to_abap IMPLEMENTATION. DATA lv_m TYPE c LENGTH 2. DATA lv_d TYPE c LENGTH 2. - FIND FIRST OCCURRENCE OF REGEX '^(\d{4})-(\d{2})-(\d{2})(T|$)' "#EC NOTEXT + FIND FIRST OCCURRENCE OF REGEX '^(\d{4})-(\d{2})-(\d{2})(T|$)' IN iv_value SUBMATCHES lv_y lv_m lv_d. IF sy-subrc <> 0. @@ -1025,9 +1036,9 @@ CLASS lcl_json_to_abap IMPLEMENTATION. CONSTANTS lc_utc TYPE c LENGTH 6 VALUE 'UTC'. CONSTANTS lc_regex_ts_with_hour TYPE string - VALUE `^(\d{4})-(\d{2})-(\d{2})(T)(\d{2}):(\d{2}):(\d{2})(\+)(\d{2}):(\d{2})`. "#EC NOTEXT + VALUE `^(\d{4})-(\d{2})-(\d{2})(T)(\d{2}):(\d{2}):(\d{2})(\+)(\d{2}):(\d{2})`. CONSTANTS lc_regex_ts_utc TYPE string - VALUE `^(\d{4})-(\d{2})-(\d{2})(T)(\d{2}):(\d{2}):(\d{2})(Z|$)`. "#EC NOTEXT + VALUE `^(\d{4})-(\d{2})-(\d{2})(T)(\d{2}):(\d{2}):(\d{2})(Z|$)`. DATA: BEGIN OF ls_timestamp, @@ -1081,12 +1092,12 @@ CLASS lcl_json_to_abap IMPLEMENTATION. CASE ls_timestamp-local_sign. WHEN '-'. lv_timestamp = cl_abap_tstmp=>add( - tstmp = lv_timestamp - secs = lv_seconds_conv ). + tstmp = lv_timestamp + secs = lv_seconds_conv ). WHEN '+'. lv_timestamp = cl_abap_tstmp=>subtractsecs( - tstmp = lv_timestamp - secs = lv_seconds_conv ). + tstmp = lv_timestamp + secs = lv_seconds_conv ). ENDCASE. CATCH cx_parameter_invalid_range cx_parameter_invalid_type. @@ -1109,7 +1120,7 @@ CLASS lcl_json_to_abap IMPLEMENTATION. DATA lv_m TYPE c LENGTH 2. DATA lv_s TYPE c LENGTH 2. - FIND FIRST OCCURRENCE OF REGEX '^(\d{2}):(\d{2}):(\d{2})(T|$)' "#EC NOTEXT + FIND FIRST OCCURRENCE OF REGEX '^(\d{2}):(\d{2}):(\d{2})(T|$)' IN iv_value SUBMATCHES lv_h lv_m lv_s. IF sy-subrc <> 0. @@ -1130,12 +1141,12 @@ CLASS lcl_abap_to_json DEFINITION FINAL. CLASS-METHODS convert IMPORTING - iv_data TYPE any - is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name OPTIONAL - iv_array_index TYPE i DEFAULT 0 - ii_custom_mapping TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL - is_opts TYPE z2ui5_if_ajson=>ty_opts OPTIONAL - iv_item_order TYPE i DEFAULT 0 + iv_data TYPE any + is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name OPTIONAL + iv_array_index TYPE i DEFAULT 0 + ii_custom_mapping TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL + is_opts TYPE z2ui5_if_ajson=>ty_opts OPTIONAL + iv_item_order TYPE i DEFAULT 0 RETURNING VALUE(rt_nodes) TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING @@ -1143,13 +1154,13 @@ CLASS lcl_abap_to_json DEFINITION FINAL. CLASS-METHODS insert_with_type IMPORTING - iv_data TYPE any - iv_type TYPE z2ui5_if_ajson_types=>ty_node_type - is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name OPTIONAL - iv_array_index TYPE i DEFAULT 0 - ii_custom_mapping TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL - is_opts TYPE z2ui5_if_ajson=>ty_opts OPTIONAL - iv_item_order TYPE i DEFAULT 0 + iv_data TYPE any + iv_type TYPE z2ui5_if_ajson_types=>ty_node_type + is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name OPTIONAL + iv_array_index TYPE i DEFAULT 0 + ii_custom_mapping TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL + is_opts TYPE z2ui5_if_ajson=>ty_opts OPTIONAL + iv_item_order TYPE i DEFAULT 0 RETURNING VALUE(rt_nodes) TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING @@ -1157,17 +1168,17 @@ CLASS lcl_abap_to_json DEFINITION FINAL. CLASS-METHODS format_date IMPORTING - iv_date TYPE d + iv_date TYPE d RETURNING VALUE(rv_str) TYPE string. CLASS-METHODS format_time IMPORTING - iv_time TYPE t + iv_time TYPE t RETURNING VALUE(rv_str) TYPE string. CLASS-METHODS format_timestamp IMPORTING - iv_ts TYPE timestamp + iv_ts TYPE timestamp RETURNING VALUE(rv_str) TYPE string. @@ -1182,84 +1193,84 @@ CLASS lcl_abap_to_json DEFINITION FINAL. METHODS convert_any IMPORTING - iv_data TYPE any - io_type TYPE REF TO cl_abap_typedescr - is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name - iv_index TYPE i DEFAULT 0 + iv_data TYPE any + io_type TYPE REF TO cl_abap_typedescr + is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name + iv_index TYPE i DEFAULT 0 iv_item_order TYPE i DEFAULT 0 CHANGING - ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt + ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING z2ui5_cx_ajson_error. METHODS convert_ajson IMPORTING - io_json TYPE REF TO z2ui5_if_ajson - is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name - iv_index TYPE i DEFAULT 0 + io_json TYPE REF TO z2ui5_if_ajson + is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name + iv_index TYPE i DEFAULT 0 iv_item_order TYPE i DEFAULT 0 CHANGING - ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt + ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING z2ui5_cx_ajson_error. METHODS convert_value IMPORTING - iv_data TYPE any - io_type TYPE REF TO cl_abap_typedescr - is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name - iv_index TYPE i DEFAULT 0 + iv_data TYPE any + io_type TYPE REF TO cl_abap_typedescr + is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name + iv_index TYPE i DEFAULT 0 iv_item_order TYPE i DEFAULT 0 CHANGING - ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt + ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING z2ui5_cx_ajson_error. METHODS convert_ref IMPORTING - iv_data TYPE any - is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name - iv_index TYPE i DEFAULT 0 + iv_data TYPE any + is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name + iv_index TYPE i DEFAULT 0 iv_item_order TYPE i DEFAULT 0 CHANGING - ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt + ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING z2ui5_cx_ajson_error. METHODS convert_struc IMPORTING - iv_data TYPE any - io_type TYPE REF TO cl_abap_typedescr - is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name - iv_index TYPE i DEFAULT 0 + iv_data TYPE any + io_type TYPE REF TO cl_abap_typedescr + is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name + iv_index TYPE i DEFAULT 0 iv_item_order TYPE i DEFAULT 0 CHANGING - ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt + ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING z2ui5_cx_ajson_error. METHODS convert_table IMPORTING - iv_data TYPE any - io_type TYPE REF TO cl_abap_typedescr - is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name - iv_index TYPE i DEFAULT 0 + iv_data TYPE any + io_type TYPE REF TO cl_abap_typedescr + is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name + iv_index TYPE i DEFAULT 0 iv_item_order TYPE i DEFAULT 0 CHANGING - ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt + ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING z2ui5_cx_ajson_error. METHODS insert_value_with_type IMPORTING - iv_data TYPE any - iv_type TYPE z2ui5_if_ajson_types=>ty_node_type - io_type TYPE REF TO cl_abap_typedescr - is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name - iv_index TYPE i DEFAULT 0 + iv_data TYPE any + iv_type TYPE z2ui5_if_ajson_types=>ty_node_type + io_type TYPE REF TO cl_abap_typedescr + is_prefix TYPE z2ui5_if_ajson_types=>ty_path_name + iv_index TYPE i DEFAULT 0 iv_item_order TYPE i DEFAULT 0 CHANGING - ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt + ct_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt RAISING z2ui5_cx_ajson_error. @@ -1740,7 +1751,7 @@ INTERFACE lif_mutator_runner. IMPORTING it_source_tree TYPE z2ui5_if_ajson_types=>ty_nodes_ts EXPORTING - et_dest_tree TYPE z2ui5_if_ajson_types=>ty_nodes_ts + et_dest_tree TYPE z2ui5_if_ajson_types=>ty_nodes_ts RAISING z2ui5_cx_ajson_error. ENDINTERFACE. @@ -1754,7 +1765,7 @@ CLASS lcl_filter_runner DEFINITION FINAL. INTERFACES lif_mutator_runner. CLASS-METHODS new IMPORTING - ii_filter TYPE REF TO z2ui5_if_ajson_filter + ii_filter TYPE REF TO z2ui5_if_ajson_filter RETURNING VALUE(ro_instance) TYPE REF TO lcl_filter_runner. METHODS constructor @@ -1768,7 +1779,7 @@ CLASS lcl_filter_runner DEFINITION FINAL. METHODS walk IMPORTING - iv_path TYPE string + iv_path TYPE string CHANGING cs_parent TYPE z2ui5_if_ajson_types=>ty_node OPTIONAL RAISING @@ -1866,7 +1877,7 @@ CLASS lcl_mapper_runner DEFINITION FINAL. INTERFACES lif_mutator_runner. CLASS-METHODS new IMPORTING - ii_mapper TYPE REF TO z2ui5_if_ajson_mapping + ii_mapper TYPE REF TO z2ui5_if_ajson_mapping RETURNING VALUE(ro_instance) TYPE REF TO lcl_mapper_runner. METHODS constructor @@ -1980,7 +1991,7 @@ CLASS lcl_mutator_queue DEFINITION FINAL. VALUE(ro_instance) TYPE REF TO lcl_mutator_queue. METHODS add IMPORTING - ii_mutator TYPE REF TO lif_mutator_runner + ii_mutator TYPE REF TO lif_mutator_runner RETURNING VALUE(ro_self) TYPE REF TO lcl_mutator_queue. diff --git a/src/01/00/01/z2ui5_cl_ajson.clas.testclasses.abap b/src/01/00/01/z2ui5_cl_ajson.clas.testclasses.abap index bf0f2569..14737a1d 100644 --- a/src/01/00/01/z2ui5_cl_ajson.clas.testclasses.abap +++ b/src/01/00/01/z2ui5_cl_ajson.clas.testclasses.abap @@ -65,7 +65,7 @@ CLASS ltcl_parser_test DEFINITION FINAL CLASS-METHODS sample_json IMPORTING - iv_separator TYPE string OPTIONAL + iv_separator TYPE string OPTIONAL RETURNING VALUE(rv_json) TYPE string. @@ -146,26 +146,26 @@ CLASS ltcl_parser_test IMPLEMENTATION. cl_abap_unit_assert=>fail( 'Parsing of string w/o quotes must fail (spec)' ). CATCH z2ui5_cx_ajson_error INTO lx_err. cl_abap_unit_assert=>assert_char_cp( - act = lx_err->get_text( ) - exp = '*parsing error*' ). + act = lx_err->get_text( ) + exp = '*parsing error*' ). cl_abap_unit_assert=>assert_char_cp( - act = lx_err->location - exp = 'Line 1, Offset 1' ). + act = lx_err->location + exp = 'Line 1, Offset 1' ). ENDTRY. TRY. lt_act = mo_cut->parse( '{' && cl_abap_char_utilities=>newline - && '"ok": "abc",' && cl_abap_char_utilities=>newline - && '"error"' && cl_abap_char_utilities=>newline - && '}' ). + && '"ok": "abc",' && cl_abap_char_utilities=>newline + && '"error"' && cl_abap_char_utilities=>newline + && '}' ). cl_abap_unit_assert=>fail( 'Parsing of invalid JSON must fail (spec)' ). CATCH z2ui5_cx_ajson_error INTO lx_err. cl_abap_unit_assert=>assert_char_cp( - act = lx_err->get_text( ) - exp = '*parsing error*' ). + act = lx_err->get_text( ) + exp = '*parsing error*' ). cl_abap_unit_assert=>assert_char_cp( - act = lx_err->location - exp = 'Line 3, Offset 8' ). + act = lx_err->location + exp = 'Line 3, Offset 8' ). ENDTRY. ENDMETHOD. @@ -822,13 +822,15 @@ CLASS ltcl_utils_test IMPLEMENTATION. exp = 123 ). TRY. - lcl_utils=>validate_array_index( iv_path = 'x' iv_index = 'a' ). + lcl_utils=>validate_array_index( iv_path = 'x' + iv_index = 'a' ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error. ENDTRY. TRY. - lcl_utils=>validate_array_index( iv_path = 'x' iv_index = '0' ). + lcl_utils=>validate_array_index( iv_path = 'x' + iv_index = '0' ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error. ENDTRY. @@ -1331,8 +1333,8 @@ CLASS ltcl_reader_test IMPLEMENTATION. cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Path not found: /x' ). + act = lx->message + exp = 'Path not found: /x' ). ENDTRY. TRY. @@ -1340,8 +1342,8 @@ CLASS ltcl_reader_test IMPLEMENTATION. cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Array expected at: /' ). + act = lx->message + exp = 'Array expected at: /' ). ENDTRY. TRY. @@ -1349,8 +1351,8 @@ CLASS ltcl_reader_test IMPLEMENTATION. cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Array expected at: /a' ). + act = lx->message + exp = 'Array expected at: /a' ). ENDTRY. CREATE OBJECT lo_nodes. @@ -1363,8 +1365,8 @@ CLASS ltcl_reader_test IMPLEMENTATION. cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Cannot convert [object] to string at [/1]' ). + act = lx->message + exp = 'Cannot convert [object] to string at [/1]' ). ENDTRY. ENDMETHOD. @@ -1389,75 +1391,96 @@ CLASS ltcl_json_to_abap DEFINITION a TYPE string, b TYPE i, END OF ty_struc, - tty_struc TYPE STANDARD TABLE OF ty_struc WITH KEY a, + tty_struc TYPE STANDARD TABLE OF ty_struc WITH KEY a, tty_struc_sorted TYPE SORTED TABLE OF ty_struc WITH UNIQUE KEY a, tty_struc_hashed TYPE HASHED TABLE OF ty_struc WITH UNIQUE KEY a, BEGIN OF ty_complex, - str TYPE string, - int TYPE i, - float TYPE f, - bool TYPE abap_bool, - obj TYPE ty_struc, - tab TYPE tty_struc, + str TYPE string, + int TYPE i, + float TYPE f, + bool TYPE abap_bool, + obj TYPE ty_struc, + tab TYPE tty_struc, tab_plain TYPE string_table, tab_hashed TYPE tty_struc_hashed, - oref TYPE REF TO object, - date1 TYPE d, - date2 TYPE d, + oref TYPE REF TO object, + date1 TYPE d, + date2 TYPE d, timestamp1 TYPE timestamp, timestamp2 TYPE timestamp, timestamp3 TYPE timestamp, + timestamp4 TYPE timestampl, END OF ty_complex. METHODS to_abap_struc - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_timestamp_initial - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_value - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_array - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_array_of_arrays_simple - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_array_of_arrays - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_w_tab_of_struc - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_w_plain_tab - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_hashed_tab - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_sorted_tab - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_hashed_plain_tab - FOR TESTING + FOR TESTING + RAISING z2ui5_cx_ajson_error. + METHODS to_abap_negative + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_corresponding - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_corresponding_negative - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_corresponding_public - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_corresponding_pub_neg - FOR TESTING + FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS to_abap_time - FOR TESTING + FOR TESTING + RAISING cx_static_check. + 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 z2ui5_cl_ajson DEFINITION LOCAL FRIENDS ltcl_json_to_abap. @@ -1487,6 +1510,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( @@ -1505,6 +1529,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 @@ -1554,21 +1579,43 @@ CLASS ltcl_json_to_abap IMPLEMENTATION. act = lv_mock exp = '111111' ). -* DATA lv_mock_init TYPE t. -* -* CREATE OBJECT lo_nodes. -* lo_nodes->add( ' | |str || ' ). -* -* CREATE OBJECT lo_cut. -* lo_cut->to_abap( -* EXPORTING -* it_nodes = lo_nodes->sorted( ) -* CHANGING -* c_container = lv_mock_init ). -* -* cl_abap_unit_assert=>assert_equals( -* act = lv_mock_init -* exp = '000000' ). + DATA lv_mock_init TYPE t. + + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |str || ' ). + + CREATE OBJECT lo_cut. + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = lv_mock_init ). + + cl_abap_unit_assert=>assert_equals( + act = lv_mock_init + exp = '000000' ). + + 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. @@ -1625,8 +1672,8 @@ CLASS ltcl_json_to_abap IMPLEMENTATION. METHOD to_abap_array_of_arrays_simple. DATA lo_cut TYPE REF TO lcl_json_to_abap. - DATA lt_mock TYPE STANDARD TABLE OF string_table. - DATA lt_exp TYPE STANDARD TABLE OF string_table. + DATA lt_mock TYPE TABLE OF string_table. + DATA lt_exp TYPE TABLE OF string_table. DATA lt_tmp TYPE string_table. DATA lo_nodes TYPE REF TO lcl_nodes_helper. @@ -1659,8 +1706,8 @@ CLASS ltcl_json_to_abap IMPLEMENTATION. METHOD to_abap_array_of_arrays. DATA lo_cut TYPE REF TO lcl_json_to_abap. - DATA lt_mock TYPE STANDARD TABLE OF string_table. - DATA lt_exp TYPE STANDARD TABLE OF string_table. + DATA lt_mock TYPE TABLE OF string_table. + DATA lt_exp TYPE TABLE OF string_table. DATA lt_tmp TYPE string_table. DATA lo_nodes TYPE REF TO lcl_nodes_helper. @@ -1859,6 +1906,173 @@ CLASS ltcl_json_to_abap IMPLEMENTATION. ENDMETHOD. + METHOD to_abap_negative. + + DATA lo_cut TYPE REF TO lcl_json_to_abap. + DATA lx TYPE REF TO z2ui5_cx_ajson_error. + DATA ls_mock TYPE ty_complex. + + CREATE OBJECT lo_cut. + + DATA lo_nodes TYPE REF TO lcl_nodes_helper. + + TRY. + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |object | ' ). + lo_nodes->add( '/ |str |object | ' ). + + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = ls_mock ). + cl_abap_unit_assert=>fail( ). + CATCH z2ui5_cx_ajson_error INTO lx. + cl_abap_unit_assert=>assert_equals( + act = lx->message + exp = 'Expected structure' ). + ENDTRY. + + TRY. + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |object | ' ). + lo_nodes->add( '/ |str |array | ' ). + + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = ls_mock ). + cl_abap_unit_assert=>fail( ). + CATCH z2ui5_cx_ajson_error INTO lx. + cl_abap_unit_assert=>assert_equals( + act = lx->message + exp = 'Expected table' ). + ENDTRY. + + TRY. + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |object | ' ). + lo_nodes->add( '/ |int |str |hello ' ). + + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = ls_mock ). + cl_abap_unit_assert=>fail( ). + CATCH z2ui5_cx_ajson_error INTO lx. + cl_abap_unit_assert=>assert_equals( + act = lx->message + exp = 'Source is not a number' ). + ENDTRY. + + TRY. + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |object | ' ). + lo_nodes->add( '/ |date1 |str |baddate ' ). + + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = ls_mock ). + cl_abap_unit_assert=>fail( ). + CATCH z2ui5_cx_ajson_error INTO lx. + cl_abap_unit_assert=>assert_equals( + act = lx->message + exp = 'Unexpected date format' ). + ENDTRY. + + TRY. + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |object | ' ). + lo_nodes->add( '/ |missing |str |123 ' ). + + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = ls_mock ). + cl_abap_unit_assert=>fail( ). + CATCH z2ui5_cx_ajson_error INTO lx. + cl_abap_unit_assert=>assert_equals( + act = lx->message + exp = 'Path not found' ). + ENDTRY. + + TRY. + DATA lt_str TYPE string_table. + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |array | | ' ). + lo_nodes->add( '/ |a |str |hello |1' ). + + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = lt_str ). + cl_abap_unit_assert=>fail( ). + CATCH z2ui5_cx_ajson_error INTO lx. + cl_abap_unit_assert=>assert_equals( + act = lx->message + exp = 'Need index to access tables' ). + ENDTRY. + + TRY. + DATA lr_obj TYPE REF TO object. + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |str |hello | ' ). + + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = lr_obj ). + cl_abap_unit_assert=>fail( ). + CATCH z2ui5_cx_ajson_error INTO lx. + cl_abap_unit_assert=>assert_equals( + act = lx->message + exp = 'Cannot assign to ref' ). + ENDTRY. + + TRY. + DATA lr_data TYPE REF TO data. + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |str |hello | ' ). + + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = lr_data ). + cl_abap_unit_assert=>fail( ). + CATCH z2ui5_cx_ajson_error INTO lx. + cl_abap_unit_assert=>assert_equals( + act = lx->message + exp = 'Cannot assign to ref' ). + ENDTRY. + + TRY. + DATA lt_hashed TYPE HASHED TABLE OF string WITH UNIQUE KEY table_line. + CREATE OBJECT lo_nodes. + lo_nodes->add( ' | |array | | ' ). + lo_nodes->add( '/ |1 |str |One |1' ). + lo_nodes->add( '/ |2 |str |One |2' ). + + lo_cut->to_abap( + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = lt_hashed ). + cl_abap_unit_assert=>fail( ). + CATCH z2ui5_cx_ajson_error INTO lx. + cl_abap_unit_assert=>assert_equals( + act = lx->message + exp = 'Duplicate insertion' ). + ENDTRY. + + ENDMETHOD. METHOD to_abap_corresponding. @@ -1909,15 +2123,15 @@ CLASS ltcl_json_to_abap IMPLEMENTATION. TRY. CREATE OBJECT lo_cut. lo_cut->to_abap( - EXPORTING - it_nodes = lo_nodes->sorted( ) - CHANGING - c_container = ls_act ). + EXPORTING + it_nodes = lo_nodes->sorted( ) + CHANGING + c_container = ls_act ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Path not found' ). + act = lx->message + exp = 'Path not found' ). ENDTRY. ENDMETHOD. @@ -1984,12 +2198,177 @@ CLASS ltcl_json_to_abap IMPLEMENTATION. cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Path not found' ). + act = lx->message + exp = 'Path not found' ). ENDTRY. 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 z2ui5_cl_ajson. + DATA lv_json TYPE string. + + lv_json = + '[' && + ' {' && + ' "foo": "abc",' && + ' "bar": "123"' && + ' },' && + ' {' && + ' "foo": "cde"' && + ' }' && + ']'. + + lo_ajson = z2ui5_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 z2ui5_cl_ajson. + DATA lv_json TYPE string. + + lv_json = + '[' && + ' {' && + ' "foo": "abc",' && + ' "bar": "123"' && + ' },' && + ' {' && + ' "foo": "cde"' && + ' }' && + ']'. + + lo_ajson = z2ui5_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 z2ui5_cl_ajson. + DATA lv_json TYPE string. + + lv_json = + '[' && + ' {' && + ' "foo": "abc",' && + ' "bar": "123"' && + ' },' && + ' {' && + ' "foo": "cde"' && + ' }' && + ']'. + + lo_ajson = z2ui5_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 z2ui5_cl_ajson. + DATA lv_json TYPE string. + + lv_json = + '[' && + ' {' && + ' "foo": "abc",' && + ' "bar": "123"' && + ' },' && + ' {' && + ' "foo": "cde"' && + ' }' && + ']'. + + lo_ajson = z2ui5_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 z2ui5_cl_ajson. + DATA lv_json TYPE string. + + lv_json = + '[' && + ' {' && + ' "foo": "abc",' && + ' "bar": "123"' && + ' },' && + ' {' && + ' "foo": "cde"' && + ' }' && + ']'. + + lo_ajson = z2ui5_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. ********************************************************************** @@ -2027,6 +2406,7 @@ CLASS ltcl_writer_test DEFINITION FINAL METHODS read_only FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS set_array_obj FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS set_with_type FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS new_array_w_keep_order_touch FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS overwrite_w_keep_order_touch FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS overwrite_w_keep_order_set FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS setx FOR TESTING RAISING z2ui5_cx_ajson_error. @@ -2036,9 +2416,9 @@ CLASS ltcl_writer_test DEFINITION FINAL METHODS set_with_type_slice IMPORTING - io_json_in TYPE REF TO z2ui5_cl_ajson + io_json_in TYPE REF TO z2ui5_cl_ajson io_json_out TYPE REF TO z2ui5_if_ajson - iv_path TYPE string + iv_path TYPE string RAISING z2ui5_cx_ajson_error. @@ -2430,7 +2810,7 @@ CLASS ltcl_writer_test IMPLEMENTATION. END OF ty_include, BEGIN OF ty_struct. INCLUDE TYPE ty_include. - TYPES: dat TYPE xstring, + TYPES: dat TYPE xstring, END OF ty_struct, ty_tab TYPE STANDARD TABLE OF ty_struct WITH KEY str. @@ -2587,67 +2967,67 @@ CLASS ltcl_writer_test IMPLEMENTATION. cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Path [/a/1] already used and is not array' ). + act = lx->message + exp = 'Path [/a/1] already used and is not array' ). ENDTRY. " push to not array TRY. li_writer->push( - iv_path = '/a/1' - iv_val = 123 ). + iv_path = '/a/1' + iv_val = 123 ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Path [/a/1] is not array' ). + act = lx->message + exp = 'Path [/a/1] is not array' ). ENDTRY. " push to not array TRY. li_writer->push( - iv_path = '/x' - iv_val = 123 ). + iv_path = '/x' + iv_val = 123 ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Path [/x] does not exist' ). + act = lx->message + exp = 'Path [/x] does not exist' ). ENDTRY. " set array item with non-numeric key TRY. li_writer->set( - iv_path = '/a/abc/x' - iv_val = 123 ). + iv_path = '/a/abc/x' + iv_val = 123 ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Cannot add non-numeric key [abc] to array [/a/]' ). + act = lx->message + exp = 'Cannot add non-numeric key [abc] to array [/a/]' ). ENDTRY. TRY. li_writer->set( - iv_path = '/a/abc' - iv_val = 123 ). + iv_path = '/a/abc' + iv_val = 123 ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Cannot add non-numeric key [abc] to array [/a/]' ). + act = lx->message + exp = 'Cannot add non-numeric key [abc] to array [/a/]' ). ENDTRY. " set array item with zero key TRY. li_writer->set( - iv_path = '/a/0' - iv_val = 123 ). + iv_path = '/a/0' + iv_val = 123 ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx. cl_abap_unit_assert=>assert_equals( - act = lx->message - exp = 'Cannot add zero key to array [/a/]' ). + act = lx->message + exp = 'Cannot add zero key to array [/a/]' ). ENDTRY. ENDMETHOD. @@ -2936,8 +3316,8 @@ CLASS ltcl_writer_test IMPLEMENTATION. TRY. li_writer->set( - iv_path = '/c' - iv_val = 'abc' ). + iv_path = '/c' + iv_val = 'abc' ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error. ENDTRY. @@ -2950,8 +3330,8 @@ CLASS ltcl_writer_test IMPLEMENTATION. TRY. li_writer->push( - iv_path = '/b' - iv_val = 'xyz' ). + iv_path = '/b' + iv_val = 'xyz' ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error. ENDTRY. @@ -3100,6 +3480,37 @@ CLASS ltcl_writer_test IMPLEMENTATION. ENDMETHOD. + METHOD new_array_w_keep_order_touch. + + DATA li_cut TYPE REF TO z2ui5_if_ajson. + + " default order adds new arrays at beginning of node (pos 0) + li_cut = z2ui5_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 = z2ui5_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 z2ui5_if_ajson. @@ -3313,22 +3724,22 @@ CLASS ltcl_integrated DEFINITION col TYPE i, END OF ty_loc, BEGIN OF ty_issue, - message TYPE string, - key TYPE string, + message TYPE string, + key TYPE string, filename TYPE string, - start TYPE ty_loc, - end TYPE ty_loc, + start TYPE ty_loc, + end TYPE ty_loc, END OF ty_issue, tt_issues TYPE STANDARD TABLE OF ty_issue WITH KEY message key, BEGIN OF ty_target, - string TYPE string, - number TYPE i, - float TYPE f, + string TYPE string, + number TYPE i, + float TYPE f, boolean TYPE abap_bool, - false TYPE abap_bool, - null TYPE string, - date TYPE string, " ??? TODO - issues TYPE tt_issues, + false TYPE abap_bool, + null TYPE string, + date TYPE string, " ??? TODO + issues TYPE tt_issues, END OF ty_target. METHODS reader FOR TESTING RAISING z2ui5_cx_ajson_error. @@ -3374,8 +3785,8 @@ CLASS ltcl_integrated IMPLEMENTATION. METHOD array_index. - DATA lt_act TYPE STANDARD TABLE OF ty_loc. - DATA lt_exp TYPE STANDARD TABLE OF ty_loc. + DATA lt_act TYPE TABLE OF ty_loc. + DATA lt_exp TYPE TABLE OF ty_loc. DATA ls_exp TYPE ty_loc. DATA lv_src TYPE string. @@ -3542,9 +3953,9 @@ CLASS ltcl_integrated IMPLEMENTATION. DATA: BEGIN OF ls_dummy, - zulu TYPE string, + zulu TYPE string, alpha TYPE string, - beta TYPE string, + beta TYPE string, END OF ls_dummy. DATA lv_act TYPE string. @@ -3687,18 +4098,18 @@ CLASS ltcl_abap_to_json DEFINITION tt_struc TYPE STANDARD TABLE OF ty_struc WITH KEY a, BEGIN OF ty_struc_complex. INCLUDE TYPE ty_struc. - TYPES: - el TYPE string, + TYPES: + el TYPE string, struc TYPE ty_struc, - tab TYPE tt_struc, - stab TYPE string_table, + tab TYPE tt_struc, + stab TYPE string_table, END OF ty_struc_complex. TYPES BEGIN OF ty_named_include. - INCLUDE TYPE ty_struc AS named_with_suffix RENAMING WITH SUFFIX _suf. + INCLUDE TYPE ty_struc AS named_with_suffix RENAMING WITH SUFFIX _suf. TYPES: - el TYPE string, + el TYPE string, END OF ty_named_include. METHODS set_ajson FOR TESTING RAISING z2ui5_cx_ajson_error. @@ -4027,7 +4438,7 @@ CLASS ltcl_abap_to_json IMPLEMENTATION. DATA lo_nodes_exp TYPE REF TO lcl_nodes_helper. DATA lt_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt. - DATA lt_tab TYPE STANDARD TABLE OF ty_struc. + DATA lt_tab TYPE TABLE OF ty_struc. FIELD-SYMBOLS LIKE LINE OF lt_tab. APPEND INITIAL LINE TO lt_tab ASSIGNING . @@ -4095,7 +4506,7 @@ CLASS ltcl_filter_test DEFINITION FINAL type TYPE z2ui5_if_ajson_filter=>ty_visit_type, END OF ty_visit_history. - DATA mt_visit_history TYPE STANDARD TABLE OF ty_visit_history. + DATA mt_visit_history TYPE TABLE OF ty_visit_history. METHODS simple_test FOR TESTING RAISING z2ui5_cx_ajson_error. METHODS array_test FOR TESTING RAISING z2ui5_cx_ajson_error. @@ -4422,13 +4833,13 @@ CLASS ltcl_mapper_test IMPLEMENTATION. TRY. z2ui5_cl_ajson=>create_from( - ii_source_json = lo_json - ii_mapper = me ). + ii_source_json = lo_json + ii_mapper = me ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx_err. cl_abap_unit_assert=>assert_char_cp( - act = lx_err->get_text( ) - exp = 'Renamed node has a duplicate @/AB' ). + act = lx_err->get_text( ) + exp = 'Renamed node has a duplicate @/AB' ). ENDTRY. ENDMETHOD. @@ -4472,13 +4883,13 @@ CLASS ltcl_mapper_test IMPLEMENTATION. TRY. z2ui5_cl_ajson=>create_from( - ii_source_json = lo_json - ii_mapper = me ). + ii_source_json = lo_json + ii_mapper = me ). cl_abap_unit_assert=>fail( ). CATCH z2ui5_cx_ajson_error INTO lx_err. cl_abap_unit_assert=>assert_char_cp( - act = lx_err->get_text( ) - exp = 'Renamed node name cannot be empty @/set_this_empty' ). + act = lx_err->get_text( ) + exp = 'Renamed node name cannot be empty @/set_this_empty' ). ENDTRY. ENDMETHOD. diff --git a/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.abap b/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.abap index a65c7513..6d7ec332 100644 --- a/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.abap +++ b/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.abap @@ -1,58 +1,58 @@ -class Z2UI5_CL_AJSON_FILTER_LIB definition - public - final - create public . +CLASS z2ui5_cl_ajson_filter_lib DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . - public section. + PUBLIC SECTION. - class-methods create_empty_filter - returning - value(ri_filter) type ref to z2ui5_if_ajson_filter - raising - z2UI5_cx_ajson_error . - class-methods create_path_filter - importing - !it_skip_paths type string_table optional - !iv_skip_paths type string optional - !iv_pattern_search type abap_bool default abap_false - returning - value(ri_filter) type ref to z2ui5_if_ajson_filter - raising - z2UI5_cx_ajson_error . - class-methods create_and_filter - importing - !it_filters type z2ui5_if_ajson_filter=>ty_filter_tab - returning - value(ri_filter) type ref to z2ui5_if_ajson_filter - raising - z2UI5_cx_ajson_error . + CLASS-METHODS create_empty_filter + RETURNING + VALUE(ri_filter) TYPE REF TO z2ui5_if_ajson_filter + RAISING + z2ui5_cx_ajson_error . + CLASS-METHODS create_path_filter + IMPORTING + !it_skip_paths TYPE string_table OPTIONAL + !iv_skip_paths TYPE string OPTIONAL + !iv_pattern_search TYPE abap_bool DEFAULT abap_false + RETURNING + VALUE(ri_filter) TYPE REF TO z2ui5_if_ajson_filter + RAISING + z2ui5_cx_ajson_error . + CLASS-METHODS create_and_filter + IMPORTING + !it_filters TYPE z2ui5_if_ajson_filter=>ty_filter_tab + RETURNING + VALUE(ri_filter) TYPE REF TO z2ui5_if_ajson_filter + RAISING + z2ui5_cx_ajson_error . - protected section. - private section. + PROTECTED SECTION. + PRIVATE SECTION. ENDCLASS. -CLASS Z2UI5_CL_AJSON_FILTER_LIB IMPLEMENTATION. +CLASS z2ui5_cl_ajson_filter_lib IMPLEMENTATION. - method create_and_filter. - create object ri_filter type lcl_and_filter - exporting + METHOD create_and_filter. + CREATE OBJECT ri_filter TYPE lcl_and_filter + EXPORTING it_filters = it_filters. - endmethod. + ENDMETHOD. - method create_empty_filter. - create object ri_filter type lcl_empty_filter. - endmethod. + METHOD create_empty_filter. + CREATE OBJECT ri_filter TYPE lcl_empty_filter. + ENDMETHOD. - method create_path_filter. - create object ri_filter type lcl_paths_filter - exporting + METHOD create_path_filter. + CREATE OBJECT ri_filter TYPE lcl_paths_filter + EXPORTING iv_pattern_search = iv_pattern_search it_skip_paths = it_skip_paths iv_skip_paths = iv_skip_paths. - endmethod. + ENDMETHOD. ENDCLASS. diff --git a/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.locals_imp.abap b/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.locals_imp.abap index 6d8f4e95..c06ef183 100644 --- a/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.locals_imp.abap +++ b/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.locals_imp.abap @@ -2,143 +2,143 @@ * FILTER EMPTY VALUES ********************************************************************** -class lcl_empty_filter definition final. - public section. - interfaces z2ui5_if_ajson_filter. -endclass. +CLASS lcl_empty_filter DEFINITION FINAL. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_filter. +ENDCLASS. -class lcl_empty_filter implementation. - method z2ui5_if_ajson_filter~keep_node. +CLASS lcl_empty_filter IMPLEMENTATION. + METHOD z2ui5_if_ajson_filter~keep_node. rv_keep = boolc( - ( iv_visit = z2ui5_if_ajson_filter=>visit_type-value and is_node-value is not initial ) or - ( iv_visit <> z2ui5_if_ajson_filter=>visit_type-value and is_node-children > 0 ) ). + ( iv_visit = z2ui5_if_ajson_filter=>visit_type-value AND is_node-value IS NOT INITIAL ) OR + ( iv_visit <> z2ui5_if_ajson_filter=>visit_type-value AND is_node-children > 0 ) ). " children = 0 on open for initially empty nodes and on close for filtered ones - endmethod. -endclass. + ENDMETHOD. +ENDCLASS. ********************************************************************** * FILTER PREDEFINED PATHS ********************************************************************** -class lcl_paths_filter definition final. - public section. - interfaces z2ui5_if_ajson_filter. - methods constructor - importing - it_skip_paths type string_table optional - iv_skip_paths type string optional - iv_pattern_search type abap_bool - raising - z2UI5_cx_ajson_error. - private section. - data mt_skip_paths type hashed table of string with unique key table_line. - data mv_pattern_search type abap_bool. -endclass. +CLASS lcl_paths_filter DEFINITION FINAL. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_filter. + METHODS constructor + IMPORTING + it_skip_paths TYPE string_table OPTIONAL + iv_skip_paths TYPE string OPTIONAL + iv_pattern_search TYPE abap_bool + RAISING + z2ui5_cx_ajson_error. + PRIVATE SECTION. + DATA mt_skip_paths TYPE HASHED TABLE OF string WITH UNIQUE KEY table_line. + DATA mv_pattern_search TYPE abap_bool. +ENDCLASS. -class lcl_paths_filter implementation. +CLASS lcl_paths_filter IMPLEMENTATION. - method z2ui5_if_ajson_filter~keep_node. + METHOD z2ui5_if_ajson_filter~keep_node. - data lv_full_path type string. - field-symbols

like line of mt_skip_paths. + DATA lv_full_path TYPE string. + FIELD-SYMBOLS

LIKE LINE OF mt_skip_paths. lv_full_path = is_node-path && is_node-name. - if mv_pattern_search = abap_true. + IF mv_pattern_search = abap_true. rv_keep = abap_true. - loop at mt_skip_paths assigning

. - if lv_full_path cp

. + LOOP AT mt_skip_paths ASSIGNING

. + IF lv_full_path CP

. rv_keep = abap_false. - exit. - endif. - endloop. - else. - read table mt_skip_paths with key table_line = lv_full_path transporting no fields. + EXIT. + ENDIF. + ENDLOOP. + ELSE. + READ TABLE mt_skip_paths WITH KEY table_line = lv_full_path TRANSPORTING NO FIELDS. rv_keep = boolc( sy-subrc <> 0 ). - endif. + ENDIF. - endmethod. + ENDMETHOD. - method constructor. + METHOD constructor. - data lv_s type string. - data lt_tab type string_table. - field-symbols type string. + DATA lv_s TYPE string. + DATA lt_tab TYPE string_table. + FIELD-SYMBOLS TYPE string. - if boolc( iv_skip_paths is initial ) = boolc( it_skip_paths is initial ). " XOR - z2UI5_cx_ajson_error=>raise( 'no filter path specified' ). - endif. + IF boolc( iv_skip_paths IS INITIAL ) = boolc( it_skip_paths IS INITIAL ). " XOR + z2ui5_cx_ajson_error=>raise( 'no filter path specified' ). + ENDIF. - loop at it_skip_paths into lv_s. + LOOP AT it_skip_paths INTO lv_s. lv_s = to_lower( lv_s ). - append lv_s to lt_tab. - endloop. + APPEND lv_s TO lt_tab. + ENDLOOP. - if iv_skip_paths is not initial. - split iv_skip_paths at ',' into table lt_tab. - loop at lt_tab assigning . - if is initial. - delete lt_tab index sy-tabix. - continue. - endif. + IF iv_skip_paths IS NOT INITIAL. + SPLIT iv_skip_paths AT ',' INTO TABLE lt_tab. + LOOP AT lt_tab ASSIGNING . + IF IS INITIAL. + DELETE lt_tab INDEX sy-tabix. + CONTINUE. + ENDIF. = condense( to_lower( ) ). - endloop. - endif. + ENDLOOP. + ENDIF. - sort lt_tab by table_line. - delete adjacent duplicates from lt_tab. + SORT lt_tab BY table_line. + DELETE ADJACENT DUPLICATES FROM lt_tab. mt_skip_paths = lt_tab. mv_pattern_search = iv_pattern_search. - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. ********************************************************************** * MULTI FILTER ********************************************************************** -class lcl_and_filter definition final. - public section. - interfaces z2ui5_if_ajson_filter. - methods constructor - importing - it_filters type z2ui5_if_ajson_filter=>ty_filter_tab - raising - z2UI5_cx_ajson_error. - private section. - data mt_filters type z2ui5_if_ajson_filter=>ty_filter_tab. -endclass. +CLASS lcl_and_filter DEFINITION FINAL. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_filter. + METHODS constructor + IMPORTING + it_filters TYPE z2ui5_if_ajson_filter=>ty_filter_tab + RAISING + z2ui5_cx_ajson_error. + PRIVATE SECTION. + DATA mt_filters TYPE z2ui5_if_ajson_filter=>ty_filter_tab. +ENDCLASS. -class lcl_and_filter implementation. +CLASS lcl_and_filter IMPLEMENTATION. - method z2ui5_if_ajson_filter~keep_node. + METHOD z2ui5_if_ajson_filter~keep_node. - data li_filter like line of mt_filters. + DATA li_filter LIKE LINE OF mt_filters. rv_keep = abap_true. - loop at mt_filters into li_filter. + LOOP AT mt_filters INTO li_filter. rv_keep = li_filter->keep_node( is_node = is_node iv_visit = iv_visit ). - if rv_keep = abap_false. - return. - endif. - endloop. + IF rv_keep = abap_false. + RETURN. + ENDIF. + ENDLOOP. - endmethod. + ENDMETHOD. - method constructor. + METHOD constructor. - data li_filter like line of it_filters. + DATA li_filter LIKE LINE OF it_filters. - loop at it_filters into li_filter where table_line is bound. - append li_filter to mt_filters. - endloop. + LOOP AT it_filters INTO li_filter WHERE table_line IS BOUND. + APPEND li_filter TO mt_filters. + ENDLOOP. - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. diff --git a/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.testclasses.abap b/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.testclasses.abap index a8180db2..49d8cd57 100644 --- a/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.testclasses.abap +++ b/src/01/00/01/z2ui5_cl_ajson_filter_lib.clas.testclasses.abap @@ -1,24 +1,24 @@ -class ltcl_filters_test definition final - for testing - risk level harmless - duration short. - private section. - methods empty_filter_simple for testing raising z2UI5_cx_ajson_error. - methods empty_filter_deep for testing raising z2UI5_cx_ajson_error. - methods path_filter for testing raising z2UI5_cx_ajson_error. - methods path_filter_string for testing raising z2UI5_cx_ajson_error. - methods path_filter_w_patterns for testing raising z2UI5_cx_ajson_error. - methods path_filter_deep for testing raising z2UI5_cx_ajson_error. - methods and_filter for testing raising z2UI5_cx_ajson_error. -endclass. +CLASS ltcl_filters_test DEFINITION FINAL + FOR TESTING + RISK LEVEL HARMLESS + DURATION SHORT. + PRIVATE SECTION. + METHODS empty_filter_simple FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS empty_filter_deep FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS path_filter FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS path_filter_string FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS path_filter_w_patterns FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS path_filter_deep FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS and_filter FOR TESTING RAISING z2ui5_cx_ajson_error. +ENDCLASS. -class ltcl_filters_test implementation. +CLASS ltcl_filters_test IMPLEMENTATION. - method empty_filter_simple. + METHOD empty_filter_simple. - data li_json type ref to z2ui5_if_ajson. - data li_json_filtered type ref to z2ui5_if_ajson. + DATA li_json TYPE REF TO z2ui5_if_ajson. + DATA li_json_filtered TYPE REF TO z2ui5_if_ajson. li_json = z2ui5_cl_ajson=>create_empty( ). li_json->set( @@ -42,12 +42,12 @@ class ltcl_filters_test implementation. act = li_json_filtered->stringify( ) exp = '{"a":"1","c":"3"}' ). - endmethod. + ENDMETHOD. - method empty_filter_deep. + METHOD empty_filter_deep. - data li_json type ref to z2ui5_if_ajson. - data li_json_filtered type ref to z2ui5_if_ajson. + DATA li_json TYPE REF TO z2ui5_if_ajson. + DATA li_json_filtered TYPE REF TO z2ui5_if_ajson. li_json = z2ui5_cl_ajson=>create_empty( ). li_json->set( @@ -71,15 +71,15 @@ class ltcl_filters_test implementation. act = li_json_filtered->stringify( ) exp = '{"a":"1"}' ). - endmethod. + ENDMETHOD. - method path_filter. + METHOD path_filter. - data li_json type ref to z2ui5_if_ajson. - data li_json_filtered type ref to z2ui5_if_ajson. - data lt_paths type string_table. + DATA li_json TYPE REF TO z2ui5_if_ajson. + DATA li_json_filtered TYPE REF TO z2ui5_if_ajson. + DATA lt_paths TYPE string_table. - append '/b/c' to lt_paths. + APPEND '/b/c' TO lt_paths. li_json = z2ui5_cl_ajson=>create_empty( ). li_json->set( @@ -100,12 +100,12 @@ class ltcl_filters_test implementation. act = li_json_filtered->stringify( ) exp = '{"a":"1","b":{},"c":{"d":"3"}}' ). - endmethod. + ENDMETHOD. - method path_filter_string. + METHOD path_filter_string. - data li_json type ref to z2ui5_if_ajson. - data li_json_filtered type ref to z2ui5_if_ajson. + DATA li_json TYPE REF TO z2ui5_if_ajson. + DATA li_json_filtered TYPE REF TO z2ui5_if_ajson. li_json = z2ui5_cl_ajson=>create_empty( ). li_json->set( @@ -126,12 +126,12 @@ class ltcl_filters_test implementation. act = li_json_filtered->stringify( ) exp = '{"a":"1","b":{},"c":{}}' ). - endmethod. + ENDMETHOD. - method path_filter_w_patterns. + METHOD path_filter_w_patterns. - data li_json type ref to z2ui5_if_ajson. - data li_json_filtered type ref to z2ui5_if_ajson. + DATA li_json TYPE REF TO z2ui5_if_ajson. + DATA li_json_filtered TYPE REF TO z2ui5_if_ajson. li_json = z2ui5_cl_ajson=>create_empty( ). li_json->set( @@ -160,15 +160,15 @@ class ltcl_filters_test implementation. act = li_json_filtered->stringify( ) exp = '{"a":"1","b":{},"c":{"d":"3"}}' ). - endmethod. + ENDMETHOD. - method path_filter_deep. + METHOD path_filter_deep. - data li_json type ref to z2ui5_if_ajson. - data li_json_filtered type ref to z2ui5_if_ajson. - data lt_paths type string_table. + DATA li_json TYPE REF TO z2ui5_if_ajson. + DATA li_json_filtered TYPE REF TO z2ui5_if_ajson. + DATA lt_paths TYPE string_table. - append '/b' to lt_paths. + APPEND '/b' TO lt_paths. li_json = z2ui5_cl_ajson=>create_empty( ). li_json->set( @@ -192,16 +192,16 @@ class ltcl_filters_test implementation. act = li_json_filtered->stringify( ) exp = '{"a":"1","c":{"d":"3"}}' ). - endmethod. + ENDMETHOD. - method and_filter. + METHOD and_filter. - data li_json type ref to z2ui5_if_ajson. - data li_json_filtered type ref to z2ui5_if_ajson. - data lt_filters type z2ui5_if_ajson_filter=>ty_filter_tab. + DATA li_json TYPE REF TO z2ui5_if_ajson. + DATA li_json_filtered TYPE REF TO z2ui5_if_ajson. + DATA lt_filters TYPE z2ui5_if_ajson_filter=>ty_filter_tab. - append z2ui5_cl_ajson_filter_lib=>create_empty_filter( ) to lt_filters. - append z2ui5_cl_ajson_filter_lib=>create_path_filter( iv_skip_paths = '/c' ) to lt_filters. + APPEND z2ui5_cl_ajson_filter_lib=>create_empty_filter( ) TO lt_filters. + APPEND z2ui5_cl_ajson_filter_lib=>create_path_filter( iv_skip_paths = '/c' ) TO lt_filters. li_json = z2ui5_cl_ajson=>create_empty( ). li_json->set( @@ -225,6 +225,6 @@ class ltcl_filters_test implementation. act = li_json_filtered->stringify( ) exp = '{"a":"1"}' ). - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. diff --git a/src/01/00/01/z2ui5_cl_ajson_mapping.clas.abap b/src/01/00/01/z2ui5_cl_ajson_mapping.clas.abap index 125df264..d6ba9b9d 100644 --- a/src/01/00/01/z2ui5_cl_ajson_mapping.clas.abap +++ b/src/01/00/01/z2ui5_cl_ajson_mapping.clas.abap @@ -1,156 +1,156 @@ -class z2ui5_cl_ajson_mapping definition - public - final - create public. +CLASS z2ui5_cl_ajson_mapping DEFINITION + PUBLIC + FINAL + CREATE PUBLIC. - public section. + PUBLIC SECTION. - constants: - begin of rename_by, - attr_name type i value 0, - full_path type i value 1, - pattern type i value 2, + CONSTANTS: + BEGIN OF rename_by, + attr_name TYPE i VALUE 0, + full_path TYPE i VALUE 1, + pattern TYPE i VALUE 2, " regex type i value 3, " TODO add if needed in future - end of rename_by. + END OF rename_by. - class-methods create_camel_case " DEPRECATED - importing - it_mapping_fields type z2ui5_if_ajson_mapping=>ty_mapping_fields optional - iv_first_json_upper type abap_bool default abap_true - returning - value(ri_mapping) type ref to z2ui5_if_ajson_mapping. + CLASS-METHODS create_camel_case " DEPRECATED + IMPORTING + it_mapping_fields TYPE z2ui5_if_ajson_mapping=>ty_mapping_fields OPTIONAL + iv_first_json_upper TYPE abap_bool DEFAULT abap_true + RETURNING + VALUE(ri_mapping) TYPE REF TO z2ui5_if_ajson_mapping. - class-methods create_upper_case - importing - it_mapping_fields type z2ui5_if_ajson_mapping=>ty_mapping_fields optional - returning - value(ri_mapping) type ref to z2ui5_if_ajson_mapping. + CLASS-METHODS create_upper_case + IMPORTING + it_mapping_fields TYPE z2ui5_if_ajson_mapping=>ty_mapping_fields OPTIONAL + RETURNING + VALUE(ri_mapping) TYPE REF TO z2ui5_if_ajson_mapping. - class-methods create_lower_case - importing - it_mapping_fields type z2ui5_if_ajson_mapping=>ty_mapping_fields optional - returning - value(ri_mapping) type ref to z2ui5_if_ajson_mapping. + CLASS-METHODS create_lower_case + IMPORTING + it_mapping_fields TYPE z2ui5_if_ajson_mapping=>ty_mapping_fields OPTIONAL + RETURNING + VALUE(ri_mapping) TYPE REF TO z2ui5_if_ajson_mapping. - class-methods create_field_mapping " DEPRECATED - importing - it_mapping_fields type z2ui5_if_ajson_mapping=>ty_mapping_fields - returning - value(ri_mapping) type ref to z2ui5_if_ajson_mapping. + CLASS-METHODS create_field_mapping " DEPRECATED + IMPORTING + it_mapping_fields TYPE z2ui5_if_ajson_mapping=>ty_mapping_fields + RETURNING + VALUE(ri_mapping) TYPE REF TO z2ui5_if_ajson_mapping. - class-methods create_rename - importing - it_rename_map type z2ui5_if_ajson_mapping=>tty_rename_map - iv_rename_by type i default rename_by-attr_name - returning - value(ri_mapping) type ref to z2ui5_if_ajson_mapping. + CLASS-METHODS create_rename + IMPORTING + it_rename_map TYPE z2ui5_if_ajson_mapping=>tty_rename_map + iv_rename_by TYPE i DEFAULT rename_by-attr_name + RETURNING + VALUE(ri_mapping) TYPE REF TO z2ui5_if_ajson_mapping. - class-methods create_compound_mapper - importing - ii_mapper1 type ref to z2ui5_if_ajson_mapping optional - ii_mapper2 type ref to z2ui5_if_ajson_mapping optional - ii_mapper3 type ref to z2ui5_if_ajson_mapping optional - it_more type z2ui5_if_ajson_mapping=>ty_table_of optional - returning - value(ri_mapping) type ref to z2ui5_if_ajson_mapping. + CLASS-METHODS create_compound_mapper + IMPORTING + ii_mapper1 TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL + ii_mapper2 TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL + ii_mapper3 TYPE REF TO z2ui5_if_ajson_mapping OPTIONAL + it_more TYPE z2ui5_if_ajson_mapping=>ty_table_of OPTIONAL + RETURNING + VALUE(ri_mapping) TYPE REF TO z2ui5_if_ajson_mapping. - class-methods create_to_snake_case - returning - value(ri_mapping) type ref to z2ui5_if_ajson_mapping. + CLASS-METHODS create_to_snake_case + RETURNING + VALUE(ri_mapping) TYPE REF TO z2ui5_if_ajson_mapping. - class-methods create_to_camel_case - importing - iv_first_json_upper type abap_bool default abap_false - returning - value(ri_mapping) type ref to z2ui5_if_ajson_mapping. + CLASS-METHODS create_to_camel_case + IMPORTING + iv_first_json_upper TYPE abap_bool DEFAULT abap_false + RETURNING + VALUE(ri_mapping) TYPE REF TO z2ui5_if_ajson_mapping. - protected section. + PROTECTED SECTION. - private section. + PRIVATE SECTION. ENDCLASS. -CLASS Z2UI5_CL_AJSON_MAPPING IMPLEMENTATION. +CLASS z2ui5_cl_ajson_mapping IMPLEMENTATION. - method create_camel_case. + METHOD create_camel_case. - create object ri_mapping type lcl_mapping_camel - exporting + CREATE OBJECT ri_mapping TYPE lcl_mapping_camel + EXPORTING it_mapping_fields = it_mapping_fields iv_first_json_upper = iv_first_json_upper. - endmethod. + ENDMETHOD. - method create_compound_mapper. + METHOD create_compound_mapper. - data lt_queue type z2ui5_if_ajson_mapping=>ty_table_of. + DATA lt_queue TYPE z2ui5_if_ajson_mapping=>ty_table_of. - append ii_mapper1 to lt_queue. - append ii_mapper2 to lt_queue. - append ii_mapper3 to lt_queue. - append lines of it_more to lt_queue. - delete lt_queue where table_line is initial. + APPEND ii_mapper1 TO lt_queue. + APPEND ii_mapper2 TO lt_queue. + APPEND ii_mapper3 TO lt_queue. + APPEND LINES OF it_more TO lt_queue. + DELETE lt_queue WHERE table_line IS INITIAL. - create object ri_mapping type lcl_compound_mapper - exporting + CREATE OBJECT ri_mapping TYPE lcl_compound_mapper + EXPORTING it_queue = lt_queue. - endmethod. + ENDMETHOD. - method create_field_mapping. + METHOD create_field_mapping. - create object ri_mapping type lcl_mapping_fields - exporting + CREATE OBJECT ri_mapping TYPE lcl_mapping_fields + EXPORTING it_mapping_fields = it_mapping_fields. - endmethod. + ENDMETHOD. - method create_lower_case. + METHOD create_lower_case. - create object ri_mapping type lcl_mapping_to_lower - exporting + CREATE OBJECT ri_mapping TYPE lcl_mapping_to_lower + EXPORTING it_mapping_fields = it_mapping_fields. - endmethod. + ENDMETHOD. - method create_rename. + METHOD create_rename. - create object ri_mapping type lcl_rename - exporting + CREATE OBJECT ri_mapping TYPE lcl_rename + EXPORTING it_rename_map = it_rename_map iv_rename_by = iv_rename_by. - endmethod. + ENDMETHOD. - method create_to_camel_case. + METHOD create_to_camel_case. - create object ri_mapping type lcl_to_camel - exporting + CREATE OBJECT ri_mapping TYPE lcl_to_camel + EXPORTING iv_first_json_upper = iv_first_json_upper. - endmethod. + ENDMETHOD. - method create_to_snake_case. + METHOD create_to_snake_case. - create object ri_mapping type lcl_to_snake. + CREATE OBJECT ri_mapping TYPE lcl_to_snake. - endmethod. + ENDMETHOD. - method create_upper_case. + METHOD create_upper_case. - create object ri_mapping type lcl_mapping_to_upper - exporting + CREATE OBJECT ri_mapping TYPE lcl_mapping_to_upper + EXPORTING it_mapping_fields = it_mapping_fields. - endmethod. + ENDMETHOD. ENDCLASS. diff --git a/src/01/00/01/z2ui5_cl_ajson_mapping.clas.locals_def.abap b/src/01/00/01/z2ui5_cl_ajson_mapping.clas.locals_def.abap index edcc7934..5bbcd890 100644 --- a/src/01/00/01/z2ui5_cl_ajson_mapping.clas.locals_def.abap +++ b/src/01/00/01/z2ui5_cl_ajson_mapping.clas.locals_def.abap @@ -1,116 +1,116 @@ -class lcl_mapping_fields definition. +CLASS lcl_mapping_fields DEFINITION. - public section. - interfaces z2ui5_if_ajson_mapping. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_mapping. - methods constructor - importing - it_mapping_fields type z2ui5_if_ajson_mapping~ty_mapping_fields optional. + METHODS constructor + IMPORTING + it_mapping_fields TYPE z2ui5_if_ajson_mapping~ty_mapping_fields OPTIONAL. - protected section. + PROTECTED SECTION. - private section. - data mt_mapping_fields type z2ui5_if_ajson_mapping~ty_mapping_fields. + PRIVATE SECTION. + DATA mt_mapping_fields TYPE z2ui5_if_ajson_mapping~ty_mapping_fields. -endclass. +ENDCLASS. -class lcl_rename definition. +CLASS lcl_rename DEFINITION. - public section. - interfaces z2ui5_if_ajson_mapping. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_mapping. - methods constructor - importing - it_rename_map type z2ui5_if_ajson_mapping~tty_rename_map - iv_rename_by type i. + METHODS constructor + IMPORTING + it_rename_map TYPE z2ui5_if_ajson_mapping~tty_rename_map + iv_rename_by TYPE i. - protected section. + PROTECTED SECTION. - private section. - data mt_rename_map type z2ui5_if_ajson_mapping~tty_rename_map. - data mv_rename_by type i. + PRIVATE SECTION. + DATA mt_rename_map TYPE z2ui5_if_ajson_mapping~tty_rename_map. + DATA mv_rename_by TYPE i. -endclass. +ENDCLASS. -class lcl_mapping_to_upper definition. +CLASS lcl_mapping_to_upper DEFINITION. - public section. - interfaces z2ui5_if_ajson_mapping. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_mapping. - methods constructor - importing - it_mapping_fields type z2ui5_if_ajson_mapping~ty_mapping_fields optional. + METHODS constructor + IMPORTING + it_mapping_fields TYPE z2ui5_if_ajson_mapping~ty_mapping_fields OPTIONAL. - protected section. + PROTECTED SECTION. - private section. - data mi_mapping_fields type ref to z2ui5_if_ajson_mapping. + PRIVATE SECTION. + DATA mi_mapping_fields TYPE REF TO z2ui5_if_ajson_mapping. -endclass. +ENDCLASS. -class lcl_mapping_to_lower definition. +CLASS lcl_mapping_to_lower DEFINITION. - public section. - interfaces z2ui5_if_ajson_mapping. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_mapping. - methods constructor - importing - it_mapping_fields type z2ui5_if_ajson_mapping~ty_mapping_fields optional. + METHODS constructor + IMPORTING + it_mapping_fields TYPE z2ui5_if_ajson_mapping~ty_mapping_fields OPTIONAL. - protected section. + PROTECTED SECTION. - private section. - data mi_mapping_fields type ref to z2ui5_if_ajson_mapping. + PRIVATE SECTION. + DATA mi_mapping_fields TYPE REF TO z2ui5_if_ajson_mapping. -endclass. +ENDCLASS. -class lcl_mapping_camel definition. +CLASS lcl_mapping_camel DEFINITION. - public section. - interfaces z2ui5_if_ajson_mapping. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_mapping. - methods constructor - importing - it_mapping_fields type z2ui5_if_ajson_mapping~ty_mapping_fields optional - iv_first_json_upper type abap_bool default abap_true. + METHODS constructor + IMPORTING + it_mapping_fields TYPE z2ui5_if_ajson_mapping~ty_mapping_fields OPTIONAL + iv_first_json_upper TYPE abap_bool DEFAULT abap_true. - protected section. + PROTECTED SECTION. - private section. - data mv_first_json_upper type abap_bool. - data mi_mapping_fields type ref to z2ui5_if_ajson_mapping. + PRIVATE SECTION. + DATA mv_first_json_upper TYPE abap_bool. + DATA mi_mapping_fields TYPE REF TO z2ui5_if_ajson_mapping. -endclass. +ENDCLASS. -class lcl_compound_mapper definition. +CLASS lcl_compound_mapper DEFINITION. - public section. - interfaces z2ui5_if_ajson_mapping. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_mapping. - methods constructor - importing - it_queue type z2ui5_if_ajson_mapping=>ty_table_of. + METHODS constructor + IMPORTING + it_queue TYPE z2ui5_if_ajson_mapping=>ty_table_of. - protected section. + PROTECTED SECTION. - private section. - data mt_queue type z2ui5_if_ajson_mapping=>ty_table_of. + PRIVATE SECTION. + DATA mt_queue TYPE z2ui5_if_ajson_mapping=>ty_table_of. -endclass. +ENDCLASS. -class lcl_to_snake definition. - public section. - interfaces z2ui5_if_ajson_mapping. -endclass. +CLASS lcl_to_snake DEFINITION. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_mapping. +ENDCLASS. -class lcl_to_camel definition. - public section. - interfaces z2ui5_if_ajson_mapping. - methods constructor - importing - iv_first_json_upper type abap_bool. - private section. - data mv_first_json_upper type abap_bool. -endclass. +CLASS lcl_to_camel DEFINITION. + PUBLIC SECTION. + INTERFACES z2ui5_if_ajson_mapping. + METHODS constructor + IMPORTING + iv_first_json_upper TYPE abap_bool. + PRIVATE SECTION. + DATA mv_first_json_upper TYPE abap_bool. +ENDCLASS. diff --git a/src/01/00/01/z2ui5_cl_ajson_mapping.clas.locals_imp.abap b/src/01/00/01/z2ui5_cl_ajson_mapping.clas.locals_imp.abap index 337c52af..2b075e87 100644 --- a/src/01/00/01/z2ui5_cl_ajson_mapping.clas.locals_imp.abap +++ b/src/01/00/01/z2ui5_cl_ajson_mapping.clas.locals_imp.abap @@ -1,335 +1,341 @@ -class lcl_mapping_fields implementation. "DEPRECATED +CLASS lcl_mapping_fields IMPLEMENTATION. "DEPRECATED - method constructor. + METHOD constructor. - data ls_mapping_field like line of mt_mapping_fields. + DATA ls_mapping_field LIKE LINE OF mt_mapping_fields. - loop at it_mapping_fields into ls_mapping_field. + LOOP AT it_mapping_fields INTO ls_mapping_field. ls_mapping_field-abap = to_upper( ls_mapping_field-abap ). - insert ls_mapping_field into table mt_mapping_fields. - endloop. + INSERT ls_mapping_field INTO TABLE mt_mapping_fields. + ENDLOOP. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_abap. + METHOD z2ui5_if_ajson_mapping~to_abap. - data ls_mapping_field like line of mt_mapping_fields. + DATA ls_mapping_field LIKE LINE OF mt_mapping_fields. - read table mt_mapping_fields into ls_mapping_field - with key json components json = iv_name. - if sy-subrc = 0. + READ TABLE mt_mapping_fields INTO ls_mapping_field + WITH KEY json COMPONENTS json = iv_name. + IF sy-subrc = 0. rv_result = ls_mapping_field-abap. - endif. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_json. + METHOD z2ui5_if_ajson_mapping~to_json. - data lv_field type string. - data ls_mapping_field like line of mt_mapping_fields. + DATA lv_field TYPE string. + DATA ls_mapping_field LIKE LINE OF mt_mapping_fields. lv_field = to_upper( iv_name ). - read table mt_mapping_fields into ls_mapping_field - with key abap components abap = lv_field. - if sy-subrc = 0. + READ TABLE mt_mapping_fields INTO ls_mapping_field + WITH KEY abap COMPONENTS abap = lv_field. + IF sy-subrc = 0. rv_result = ls_mapping_field-json. - endif. + ENDIF. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~rename_node. + METHOD z2ui5_if_ajson_mapping~rename_node. - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class lcl_rename implementation. +CLASS lcl_rename IMPLEMENTATION. - method constructor. + METHOD constructor. mt_rename_map = it_rename_map. mv_rename_by = iv_rename_by. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_abap. - endmethod. + METHOD z2ui5_if_ajson_mapping~to_abap. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_json. - endmethod. + METHOD z2ui5_if_ajson_mapping~to_json. + ENDMETHOD. - method z2ui5_if_ajson_mapping~rename_node. + METHOD z2ui5_if_ajson_mapping~rename_node. - data lv_full_path type string. - data lv_pair_found type abap_bool. - field-symbols like line of mt_rename_map. + DATA lv_full_path TYPE string. + DATA lv_pair_found TYPE abap_bool. + FIELD-SYMBOLS LIKE LINE OF mt_rename_map. - case mv_rename_by. - when z2ui5_cl_ajson_mapping=>rename_by-attr_name. - read table mt_rename_map assigning with table key by_name components from = cv_name. + CASE mv_rename_by. + WHEN z2ui5_cl_ajson_mapping=>rename_by-attr_name. + READ TABLE mt_rename_map ASSIGNING WITH TABLE KEY by_name COMPONENTS from = cv_name. lv_pair_found = boolc( sy-subrc = 0 ). - when z2ui5_cl_ajson_mapping=>rename_by-full_path. + WHEN z2ui5_cl_ajson_mapping=>rename_by-full_path. lv_full_path = is_node-path && cv_name. - read table mt_rename_map assigning with table key by_name components from = lv_full_path. + READ TABLE mt_rename_map ASSIGNING WITH TABLE KEY by_name COMPONENTS from = lv_full_path. lv_pair_found = boolc( sy-subrc = 0 ). - when z2ui5_cl_ajson_mapping=>rename_by-pattern. + WHEN z2ui5_cl_ajson_mapping=>rename_by-pattern. lv_full_path = is_node-path && cv_name. - loop at mt_rename_map assigning . - if lv_full_path cp -from. + LOOP AT mt_rename_map ASSIGNING . + IF lv_full_path CP -from. lv_pair_found = abap_true. - exit. - endif. - endloop. - when others. + EXIT. + ENDIF. + ENDLOOP. + WHEN OTHERS. lv_pair_found = abap_false. " No rename - endcase. + ENDCASE. - if lv_pair_found = abap_true. + IF lv_pair_found = abap_true. cv_name = -to. - endif. + ENDIF. - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class lcl_mapping_to_upper implementation. +CLASS lcl_mapping_to_upper IMPLEMENTATION. - method constructor. + METHOD constructor. mi_mapping_fields = z2ui5_cl_ajson_mapping=>create_field_mapping( it_mapping_fields ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_abap. + METHOD z2ui5_if_ajson_mapping~to_abap. - rv_result = mi_mapping_fields->to_abap( iv_path = iv_path iv_name = iv_name ). + rv_result = mi_mapping_fields->to_abap( iv_path = iv_path + iv_name = iv_name ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_json. + METHOD z2ui5_if_ajson_mapping~to_json. - rv_result = mi_mapping_fields->to_json( iv_path = iv_path iv_name = iv_name ). + rv_result = mi_mapping_fields->to_json( iv_path = iv_path + iv_name = iv_name ). - if rv_result is not initial. " Mapping found - return. - endif. + IF rv_result IS NOT INITIAL. " Mapping found + RETURN. + ENDIF. rv_result = to_upper( iv_name ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~rename_node. + METHOD z2ui5_if_ajson_mapping~rename_node. cv_name = to_upper( cv_name ). - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class lcl_mapping_to_lower implementation. +CLASS lcl_mapping_to_lower IMPLEMENTATION. - method constructor. + METHOD constructor. mi_mapping_fields = z2ui5_cl_ajson_mapping=>create_field_mapping( it_mapping_fields ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_abap. + METHOD z2ui5_if_ajson_mapping~to_abap. - rv_result = mi_mapping_fields->to_abap( iv_path = iv_path iv_name = iv_name ). + rv_result = mi_mapping_fields->to_abap( iv_path = iv_path + iv_name = iv_name ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_json. + METHOD z2ui5_if_ajson_mapping~to_json. - rv_result = mi_mapping_fields->to_json( iv_path = iv_path iv_name = iv_name ). + rv_result = mi_mapping_fields->to_json( iv_path = iv_path + iv_name = iv_name ). - if rv_result is not initial. " Mapping found - return. - endif. + IF rv_result IS NOT INITIAL. " Mapping found + RETURN. + ENDIF. rv_result = to_lower( iv_name ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~rename_node. + METHOD z2ui5_if_ajson_mapping~rename_node. cv_name = to_lower( cv_name ). - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class lcl_mapping_camel implementation. "DEPRECATED +CLASS lcl_mapping_camel IMPLEMENTATION. "DEPRECATED - method constructor. + METHOD constructor. mi_mapping_fields = z2ui5_cl_ajson_mapping=>create_field_mapping( it_mapping_fields ). mv_first_json_upper = iv_first_json_upper. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_abap. + METHOD z2ui5_if_ajson_mapping~to_abap. - rv_result = mi_mapping_fields->to_abap( iv_path = iv_path iv_name = iv_name ). + rv_result = mi_mapping_fields->to_abap( iv_path = iv_path + iv_name = iv_name ). - if rv_result is not initial. " Mapping found - return. - endif. + IF rv_result IS NOT INITIAL. " Mapping found + RETURN. + ENDIF. rv_result = iv_name. - replace all occurrences of regex `([a-z])([A-Z])` in rv_result with `$1_$2`. "#EC NOTEXT + REPLACE ALL OCCURRENCES OF REGEX `([a-z])([A-Z])` IN rv_result WITH `$1_$2`. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_json. + METHOD z2ui5_if_ajson_mapping~to_json. - types ty_token type c length 255. - data lt_tokens TYPE STANDARD TABLE OF ty_token. - data lv_from type i. - field-symbols like line of lt_tokens. + TYPES ty_token TYPE c LENGTH 255. + DATA lt_tokens TYPE STANDARD TABLE OF ty_token. + DATA lv_from TYPE i. + FIELD-SYMBOLS LIKE LINE OF lt_tokens. - rv_result = mi_mapping_fields->to_json( iv_path = iv_path iv_name = iv_name ). + rv_result = mi_mapping_fields->to_json( iv_path = iv_path + iv_name = iv_name ). - if rv_result is not initial. " Mapping found - return. - endif. + IF rv_result IS NOT INITIAL. " Mapping found + RETURN. + ENDIF. rv_result = iv_name. - replace all occurrences of `__` in rv_result with `*`. + REPLACE ALL OCCURRENCES OF `__` IN rv_result WITH `*`. - translate rv_result to lower case. - translate rv_result using `/_:_~_`. + TRANSLATE rv_result TO LOWER CASE. + TRANSLATE rv_result USING `/_:_~_`. - if mv_first_json_upper = abap_true. + IF mv_first_json_upper = abap_true. lv_from = 1. - else. + ELSE. lv_from = 2. - endif. + ENDIF. - split rv_result at `_` into table lt_tokens. - loop at lt_tokens assigning from lv_from. - translate (1) to upper case. - endloop. + SPLIT rv_result AT `_` INTO TABLE lt_tokens. + LOOP AT lt_tokens ASSIGNING FROM lv_from. + TRANSLATE (1) TO UPPER CASE. + ENDLOOP. - concatenate lines of lt_tokens into rv_result. - replace all occurrences of `*` in rv_result with `_`. + CONCATENATE LINES OF lt_tokens INTO rv_result. + REPLACE ALL OCCURRENCES OF `*` IN rv_result WITH `_`. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~rename_node. + METHOD z2ui5_if_ajson_mapping~rename_node. - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class lcl_compound_mapper implementation. +CLASS lcl_compound_mapper IMPLEMENTATION. - method constructor. + METHOD constructor. mt_queue = it_queue. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~rename_node. + METHOD z2ui5_if_ajson_mapping~rename_node. - data ls_node like is_node. - data li_mapper like line of mt_queue. + DATA ls_node LIKE is_node. + DATA li_mapper LIKE LINE OF mt_queue. ls_node = is_node. - loop at mt_queue into li_mapper. + LOOP AT mt_queue INTO li_mapper. li_mapper->rename_node( - exporting + EXPORTING is_node = ls_node - changing + CHANGING cv_name = cv_name ). ls_node-name = cv_name. - endloop. + ENDLOOP. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_abap. + METHOD z2ui5_if_ajson_mapping~to_abap. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_json. + METHOD z2ui5_if_ajson_mapping~to_json. - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class lcl_to_snake implementation. +CLASS lcl_to_snake IMPLEMENTATION. - method z2ui5_if_ajson_mapping~rename_node. + METHOD z2ui5_if_ajson_mapping~rename_node. - replace all occurrences of regex `([a-z])([A-Z])` in cv_name with `$1_$2`. "#EC NOTEXT + REPLACE ALL OCCURRENCES OF REGEX `([a-z])([A-Z])` IN cv_name WITH `$1_$2`. cv_name = to_lower( cv_name ). - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_abap. + METHOD z2ui5_if_ajson_mapping~to_abap. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_json. + METHOD z2ui5_if_ajson_mapping~to_json. - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class lcl_to_camel implementation. +CLASS lcl_to_camel IMPLEMENTATION. - method constructor. + METHOD constructor. mv_first_json_upper = iv_first_json_upper. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~rename_node. + METHOD z2ui5_if_ajson_mapping~rename_node. - types lty_token type c length 255. - constants lc_forced_underscore_marker type c length 1 value cl_abap_char_utilities=>horizontal_tab. + TYPES lty_token TYPE c LENGTH 255. + CONSTANTS lc_forced_underscore_marker TYPE c LENGTH 1 VALUE cl_abap_char_utilities=>horizontal_tab. - data lt_tokens TYPE STANDARD TABLE OF lty_token. - data lv_from type i. - field-symbols like line of lt_tokens. + DATA lt_tokens TYPE STANDARD TABLE OF lty_token. + DATA lv_from TYPE i. + FIELD-SYMBOLS LIKE LINE OF lt_tokens. - if mv_first_json_upper = abap_true. + IF mv_first_json_upper = abap_true. lv_from = 1. - else. + ELSE. lv_from = 2. - endif. - replace all occurrences of `__` in cv_name with lc_forced_underscore_marker. " Force underscore + ENDIF. + REPLACE ALL OCCURRENCES OF `__` IN cv_name WITH lc_forced_underscore_marker. " Force underscore - split cv_name at `_` into table lt_tokens. - delete lt_tokens where table_line is initial. - loop at lt_tokens assigning from lv_from. - translate +0(1) to upper case. - endloop. + SPLIT cv_name AT `_` INTO TABLE lt_tokens. + DELETE lt_tokens WHERE table_line IS INITIAL. + LOOP AT lt_tokens ASSIGNING FROM lv_from. + TRANSLATE +0(1) TO UPPER CASE. + ENDLOOP. - concatenate lines of lt_tokens into cv_name. - replace all occurrences of lc_forced_underscore_marker in cv_name with `_`. + CONCATENATE LINES OF lt_tokens INTO cv_name. + REPLACE ALL OCCURRENCES OF lc_forced_underscore_marker IN cv_name WITH `_`. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_abap. + METHOD z2ui5_if_ajson_mapping~to_abap. - endmethod. + ENDMETHOD. - method z2ui5_if_ajson_mapping~to_json. + METHOD z2ui5_if_ajson_mapping~to_json. - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. diff --git a/src/01/00/01/z2ui5_cl_ajson_mapping.clas.testclasses.abap b/src/01/00/01/z2ui5_cl_ajson_mapping.clas.testclasses.abap index 89f8a842..3c9e9d41 100644 --- a/src/01/00/01/z2ui5_cl_ajson_mapping.clas.testclasses.abap +++ b/src/01/00/01/z2ui5_cl_ajson_mapping.clas.testclasses.abap @@ -1,84 +1,86 @@ -class ltcl_test_mappers definition final for testing - duration short - risk level harmless. +CLASS ltcl_test_mappers DEFINITION FINAL FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. - private section. - methods: - from_json_to_json for testing raising z2UI5_cx_ajson_error, - to_abap for testing raising z2UI5_cx_ajson_error, - to_json for testing raising z2UI5_cx_ajson_error, - to_json_nested_struc for testing raising z2UI5_cx_ajson_error, - to_json_nested_table for testing raising z2UI5_cx_ajson_error, - to_json_first_lower for testing raising z2UI5_cx_ajson_error. + PRIVATE SECTION. + METHODS: + from_json_to_json FOR TESTING RAISING z2ui5_cx_ajson_error, + to_abap FOR TESTING RAISING z2ui5_cx_ajson_error, + to_json FOR TESTING RAISING z2ui5_cx_ajson_error, + to_json_nested_struc FOR TESTING RAISING z2ui5_cx_ajson_error, + to_json_nested_table FOR TESTING RAISING z2ui5_cx_ajson_error, + to_json_first_lower FOR TESTING RAISING z2ui5_cx_ajson_error. - methods: - to_snake for testing raising z2UI5_cx_ajson_error, - to_camel for testing raising z2UI5_cx_ajson_error, - to_camel_1st_upper for testing raising z2UI5_cx_ajson_error, - rename_by_attr for testing raising z2UI5_cx_ajson_error, - rename_by_path for testing raising z2UI5_cx_ajson_error, - rename_by_pattern for testing raising z2UI5_cx_ajson_error, - compound_mapper for testing raising z2UI5_cx_ajson_error, - test_to_upper for testing raising z2UI5_cx_ajson_error, - test_to_lower for testing raising z2UI5_cx_ajson_error. + METHODS: + to_snake FOR TESTING RAISING z2ui5_cx_ajson_error, + to_camel FOR TESTING RAISING z2ui5_cx_ajson_error, + to_camel_1st_upper FOR TESTING RAISING z2ui5_cx_ajson_error, + rename_by_attr FOR TESTING RAISING z2ui5_cx_ajson_error, + rename_by_path FOR TESTING RAISING z2ui5_cx_ajson_error, + rename_by_pattern FOR TESTING RAISING z2ui5_cx_ajson_error, + compound_mapper FOR TESTING RAISING z2ui5_cx_ajson_error, + test_to_upper FOR TESTING RAISING z2ui5_cx_ajson_error, + test_to_lower FOR TESTING RAISING z2ui5_cx_ajson_error. -endclass. +ENDCLASS. -class ltcl_test_mappers implementation. +CLASS ltcl_test_mappers IMPLEMENTATION. - method from_json_to_json. + METHOD from_json_to_json. - data: - lo_ajson type ref to z2ui5_cl_ajson. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson. lo_ajson = z2ui5_cl_ajson=>parse( iv_json = `{"fieldData":"field_value"}` ii_custom_mapping = z2ui5_cl_ajson_mapping=>create_camel_case( iv_first_json_upper = abap_false ) ). - lo_ajson->set_string( iv_path = `/fieldData` iv_val = 'E' ). + lo_ajson->set_string( iv_path = `/fieldData` + iv_val = 'E' ). cl_abap_unit_assert=>assert_equals( act = lo_ajson->stringify( ) exp = '{"fieldData":"E"}' ). - endmethod. + ENDMETHOD. - method to_abap. + METHOD to_abap. - data: - lo_ajson type ref to z2ui5_cl_ajson, - li_mapping type ref to z2ui5_if_ajson_mapping. - data: - begin of ls_result, - field_data type string, - end of ls_result. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson, + li_mapping TYPE REF TO z2ui5_if_ajson_mapping. + DATA: + BEGIN OF ls_result, + field_data TYPE string, + END OF ls_result. li_mapping = z2ui5_cl_ajson_mapping=>create_camel_case( ). - lo_ajson = z2ui5_cl_ajson=>parse( iv_json = '{"FieldData":"field_value"}' ii_custom_mapping = li_mapping ). + lo_ajson = z2ui5_cl_ajson=>parse( iv_json = '{"FieldData":"field_value"}' + ii_custom_mapping = li_mapping ). - lo_ajson->to_abap( importing ev_container = ls_result ). + lo_ajson->to_abap( IMPORTING ev_container = ls_result ). cl_abap_unit_assert=>assert_equals( act = ls_result-field_data exp = 'field_value' ). - endmethod. + ENDMETHOD. - method to_json. + METHOD to_json. - data: - lo_ajson type ref to z2ui5_cl_ajson, - li_mapping type ref to z2ui5_if_ajson_mapping. - data: - begin of ls_result, - field_data type string, - end of ls_result. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson, + li_mapping TYPE REF TO z2ui5_if_ajson_mapping. + DATA: + BEGIN OF ls_result, + field_data TYPE string, + END OF ls_result. li_mapping = z2ui5_cl_ajson_mapping=>create_camel_case( iv_first_json_upper = abap_false ). @@ -86,27 +88,28 @@ class ltcl_test_mappers implementation. lo_ajson = z2ui5_cl_ajson=>create_empty( ii_custom_mapping = li_mapping ). - lo_ajson->set( iv_path = '/' iv_val = ls_result ). + lo_ajson->set( iv_path = '/' + iv_val = ls_result ). cl_abap_unit_assert=>assert_equals( act = lo_ajson->stringify( ) exp = '{"fieldData":"field_value"}' ). - endmethod. + ENDMETHOD. - method to_json_nested_struc. + METHOD to_json_nested_struc. - data: - lo_ajson type ref to z2ui5_cl_ajson, - li_mapping type ref to z2ui5_if_ajson_mapping. - data: - begin of ls_result, - field_data type string, - begin of struc_data, - field_more type string, - end of struc_data, - end of ls_result. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson, + li_mapping TYPE REF TO z2ui5_if_ajson_mapping. + DATA: + BEGIN OF ls_result, + field_data TYPE string, + BEGIN OF struc_data, + field_more TYPE string, + END OF struc_data, + END OF ls_result. li_mapping = z2ui5_cl_ajson_mapping=>create_camel_case( iv_first_json_upper = abap_false ). @@ -115,34 +118,35 @@ class ltcl_test_mappers implementation. lo_ajson = z2ui5_cl_ajson=>create_empty( ii_custom_mapping = li_mapping ). - lo_ajson->set( iv_path = '/' iv_val = ls_result ). + lo_ajson->set( iv_path = '/' + iv_val = ls_result ). cl_abap_unit_assert=>assert_equals( act = lo_ajson->stringify( ) exp = '{"fieldData":"field_value","strucData":{"fieldMore":"field_more"}}' ). - endmethod. + ENDMETHOD. - method to_json_nested_table. + METHOD to_json_nested_table. - data: - lo_ajson type ref to z2ui5_cl_ajson, - li_mapping type ref to z2ui5_if_ajson_mapping. - data: - lv_value type string, - begin of ls_result, - field_data type string, - begin of struc_data, - field_more type string_table, - end of struc_data, - end of ls_result. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson, + li_mapping TYPE REF TO z2ui5_if_ajson_mapping. + DATA: + lv_value TYPE string, + BEGIN OF ls_result, + field_data TYPE string, + BEGIN OF struc_data, + field_more TYPE string_table, + END OF struc_data, + END OF ls_result. li_mapping = z2ui5_cl_ajson_mapping=>create_camel_case( iv_first_json_upper = abap_false ). ls_result-field_data = 'field_value'. lv_value = 'field_more'. - insert lv_value into table ls_result-struc_data-field_more. + INSERT lv_value INTO TABLE ls_result-struc_data-field_more. lo_ajson = z2ui5_cl_ajson=>create_empty( ii_custom_mapping = li_mapping ). @@ -153,18 +157,18 @@ class ltcl_test_mappers implementation. act = lo_ajson->stringify( ) exp = '{"fieldData":"field_value","strucData":{"fieldMore":["field_more"]}}' ). - endmethod. + ENDMETHOD. - method to_json_first_lower. + METHOD to_json_first_lower. - data: - lo_ajson type ref to z2ui5_cl_ajson, - li_mapping type ref to z2ui5_if_ajson_mapping. - data: - begin of ls_result, - field_data type string, - end of ls_result. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson, + li_mapping TYPE REF TO z2ui5_if_ajson_mapping. + DATA: + BEGIN OF ls_result, + field_data TYPE string, + END OF ls_result. li_mapping = z2ui5_cl_ajson_mapping=>create_camel_case( ). @@ -172,16 +176,17 @@ class ltcl_test_mappers implementation. lo_ajson = z2ui5_cl_ajson=>create_empty( ii_custom_mapping = li_mapping ). - lo_ajson->set( iv_path = '/' iv_val = ls_result ). + lo_ajson->set( iv_path = '/' + iv_val = ls_result ). cl_abap_unit_assert=>assert_equals( act = lo_ajson->stringify( ) exp = '{"FieldData":"field_value"}' ). - endmethod. + ENDMETHOD. - method test_to_upper. + METHOD test_to_upper. cl_abap_unit_assert=>assert_equals( act = z2ui5_cl_ajson=>create_from( @@ -195,9 +200,9 @@ class ltcl_test_mappers implementation. )->stringify( ) exp = '{"A":1,"B":{"C":2}}' ). - endmethod. + ENDMETHOD. - method test_to_lower. + METHOD test_to_lower. cl_abap_unit_assert=>assert_equals( act = z2ui5_cl_ajson=>create_from( @@ -211,20 +216,20 @@ class ltcl_test_mappers implementation. )->stringify( ) exp = '{"a":1,"b":{"c":2}}' ). - endmethod. + ENDMETHOD. - method rename_by_attr. + METHOD rename_by_attr. - data lt_map type z2ui5_if_ajson_mapping=>tty_rename_map. - field-symbols like line of lt_map. + DATA lt_map TYPE z2ui5_if_ajson_mapping=>tty_rename_map. + FIELD-SYMBOLS LIKE LINE OF lt_map. - append initial line to lt_map assigning . + APPEND INITIAL LINE TO lt_map ASSIGNING . -from = 'a'. -to = 'x'. - append initial line to lt_map assigning . + APPEND INITIAL LINE TO lt_map ASSIGNING . -from = 'c'. -to = 'y'. - append initial line to lt_map assigning . + APPEND INITIAL LINE TO lt_map ASSIGNING . -from = 'd'. -to = 'z'. @@ -235,14 +240,14 @@ class ltcl_test_mappers implementation. ) )->stringify( ) exp = '{"b":{"y":2},"x":1,"z":{"e":3}}' ). - endmethod. + ENDMETHOD. - method rename_by_path. + METHOD rename_by_path. - data lt_map type z2ui5_if_ajson_mapping=>tty_rename_map. - field-symbols like line of lt_map. + DATA lt_map TYPE z2ui5_if_ajson_mapping=>tty_rename_map. + FIELD-SYMBOLS LIKE LINE OF lt_map. - append initial line to lt_map assigning . + APPEND INITIAL LINE TO lt_map ASSIGNING . -from = '/b/a'. -to = 'x'. @@ -255,14 +260,14 @@ class ltcl_test_mappers implementation. ) )->stringify( ) exp = '{"a":1,"b":{"x":2},"c":{"a":3}}' ). - endmethod. + ENDMETHOD. - method rename_by_pattern. + METHOD rename_by_pattern. - data lt_map type z2ui5_if_ajson_mapping=>tty_rename_map. - field-symbols like line of lt_map. + DATA lt_map TYPE z2ui5_if_ajson_mapping=>tty_rename_map. + FIELD-SYMBOLS LIKE LINE OF lt_map. - append initial line to lt_map assigning . + APPEND INITIAL LINE TO lt_map ASSIGNING . -from = '/*/this*'. -to = 'x'. @@ -275,14 +280,14 @@ class ltcl_test_mappers implementation. ) )->stringify( ) exp = '{"andthisnot":1,"b":{"x":2},"c":{"a":3}}' ). - endmethod. + ENDMETHOD. - method compound_mapper. + METHOD compound_mapper. - data lt_map type z2ui5_if_ajson_mapping=>tty_rename_map. - field-symbols like line of lt_map. + DATA lt_map TYPE z2ui5_if_ajson_mapping=>tty_rename_map. + FIELD-SYMBOLS LIKE LINE OF lt_map. - append initial line to lt_map assigning . + APPEND INITIAL LINE TO lt_map ASSIGNING . -from = '/b/a'. -to = 'x'. @@ -297,9 +302,9 @@ class ltcl_test_mappers implementation. )->stringify( ) exp = '{"A":1,"B":{"X":2},"C":{"A":3}}' ). - endmethod. + ENDMETHOD. - method to_snake. + METHOD to_snake. cl_abap_unit_assert=>assert_equals( act = z2ui5_cl_ajson=>create_from( @@ -308,9 +313,9 @@ class ltcl_test_mappers implementation. )->stringify( ) exp = '{"a_b":1,"bb_c":2,"c_d":{"x_y":3},"zz":4}' ). - endmethod. + ENDMETHOD. - method to_camel. + METHOD to_camel. cl_abap_unit_assert=>assert_equals( act = z2ui5_cl_ajson=>create_from( @@ -327,9 +332,9 @@ class ltcl_test_mappers implementation. )->stringify( ) exp = '{"a_b":1}' ). - endmethod. + ENDMETHOD. - method to_camel_1st_upper. + METHOD to_camel_1st_upper. cl_abap_unit_assert=>assert_equals( act = z2ui5_cl_ajson=>create_from( @@ -338,54 +343,55 @@ class ltcl_test_mappers implementation. )->stringify( ) exp = '{"AjBc":1,"BbC":2,"CD":{"XqYq":3},"Zz":4}' ). - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class ltcl_fields definition final for testing - duration short - risk level harmless. +CLASS ltcl_fields DEFINITION FINAL FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. - private section. - methods: - to_json_without_path for testing raising z2UI5_cx_ajson_error, - to_json_with_path for testing raising z2UI5_cx_ajson_error, - to_abap for testing raising z2UI5_cx_ajson_error, - to_json importing iv_path type string returning value(rv_result) type string raising z2UI5_cx_ajson_error. + PRIVATE SECTION. + METHODS: + to_json_without_path FOR TESTING RAISING z2ui5_cx_ajson_error, + to_json_with_path FOR TESTING RAISING z2ui5_cx_ajson_error, + to_abap FOR TESTING RAISING z2ui5_cx_ajson_error, + to_json IMPORTING iv_path TYPE string RETURNING VALUE(rv_result) TYPE string RAISING z2ui5_cx_ajson_error. -endclass. +ENDCLASS. -class ltcl_fields implementation. +CLASS ltcl_fields IMPLEMENTATION. - method to_abap. + METHOD to_abap. - data: - lo_ajson type ref to z2ui5_cl_ajson, - li_mapping type ref to z2ui5_if_ajson_mapping, - lt_mapping_fields type z2ui5_if_ajson_mapping=>ty_mapping_fields, - ls_mapping_field like line of lt_mapping_fields. - data: - begin of ls_result, - abap_field type string, - field type string, - end of ls_result. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson, + li_mapping TYPE REF TO z2ui5_if_ajson_mapping, + lt_mapping_fields TYPE z2ui5_if_ajson_mapping=>ty_mapping_fields, + ls_mapping_field LIKE LINE OF lt_mapping_fields. + DATA: + BEGIN OF ls_result, + abap_field TYPE string, + field TYPE string, + END OF ls_result. - clear ls_mapping_field. + CLEAR ls_mapping_field. ls_mapping_field-abap = 'ABAP_FIELD'. ls_mapping_field-json = 'json.field'. - insert ls_mapping_field into table lt_mapping_fields. + INSERT ls_mapping_field INTO TABLE lt_mapping_fields. li_mapping = z2ui5_cl_ajson_mapping=>create_field_mapping( lt_mapping_fields ). lo_ajson = - z2ui5_cl_ajson=>parse( iv_json = '{"field":"value","json.field":"field_value"}' ii_custom_mapping = li_mapping ). + z2ui5_cl_ajson=>parse( iv_json = '{"field":"value","json.field":"field_value"}' + ii_custom_mapping = li_mapping ). - lo_ajson->to_abap( importing ev_container = ls_result ). + lo_ajson->to_abap( IMPORTING ev_container = ls_result ). cl_abap_unit_assert=>assert_equals( act = ls_result-abap_field @@ -395,44 +401,44 @@ class ltcl_fields implementation. act = ls_result-field exp = 'value' ). - endmethod. + ENDMETHOD. - method to_json_without_path. + METHOD to_json_without_path. cl_abap_unit_assert=>assert_equals( act = to_json( `/` ) exp = '{"field":"value","json.field":"field_value"}' ). - endmethod. + ENDMETHOD. - method to_json_with_path. + METHOD to_json_with_path. cl_abap_unit_assert=>assert_equals( act = to_json( '/samplePath' ) exp = '{"samplePath":{"field":"value","json.field":"field_value"}}' ). - endmethod. + ENDMETHOD. - method to_json. + METHOD to_json. - data: - lo_ajson type ref to z2ui5_cl_ajson, - li_mapping type ref to z2ui5_if_ajson_mapping, - lt_mapping_fields type z2ui5_if_ajson_mapping=>ty_mapping_fields, - ls_mapping_field like line of lt_mapping_fields. - data: - begin of ls_result, - abap_field type string, - field type string, - end of ls_result. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson, + li_mapping TYPE REF TO z2ui5_if_ajson_mapping, + lt_mapping_fields TYPE z2ui5_if_ajson_mapping=>ty_mapping_fields, + ls_mapping_field LIKE LINE OF lt_mapping_fields. + DATA: + BEGIN OF ls_result, + abap_field TYPE string, + field TYPE string, + END OF ls_result. - clear ls_mapping_field. + CLEAR ls_mapping_field. ls_mapping_field-abap = 'ABAP_FIELD'. ls_mapping_field-json = 'json.field'. - insert ls_mapping_field into table lt_mapping_fields. + INSERT ls_mapping_field INTO TABLE lt_mapping_fields. li_mapping = z2ui5_cl_ajson_mapping=>create_field_mapping( lt_mapping_fields ). @@ -441,39 +447,40 @@ class ltcl_fields implementation. lo_ajson = z2ui5_cl_ajson=>create_empty( ii_custom_mapping = li_mapping ). - lo_ajson->set( iv_path = iv_path iv_val = ls_result ). + lo_ajson->set( iv_path = iv_path + iv_val = ls_result ). rv_result = lo_ajson->stringify( ). - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class ltcl_to_lower definition final for testing - duration short - risk level harmless. +CLASS ltcl_to_lower DEFINITION FINAL FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. - private section. - methods: - to_json for testing raising z2UI5_cx_ajson_error. -endclass. + PRIVATE SECTION. + METHODS: + to_json FOR TESTING RAISING z2ui5_cx_ajson_error. +ENDCLASS. -class ltcl_to_lower implementation. +CLASS ltcl_to_lower IMPLEMENTATION. - method to_json. + METHOD to_json. - data: - lo_ajson type ref to z2ui5_cl_ajson, - li_mapping type ref to z2ui5_if_ajson_mapping. - data: - begin of ls_result, - field_data type string, - end of ls_result. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson, + li_mapping TYPE REF TO z2ui5_if_ajson_mapping. + DATA: + BEGIN OF ls_result, + field_data TYPE string, + END OF ls_result. li_mapping = z2ui5_cl_ajson_mapping=>create_lower_case( ). @@ -481,41 +488,42 @@ class ltcl_to_lower implementation. lo_ajson = z2ui5_cl_ajson=>create_empty( ii_custom_mapping = li_mapping ). - lo_ajson->set( iv_path = '/' iv_val = ls_result ). + lo_ajson->set( iv_path = '/' + iv_val = ls_result ). cl_abap_unit_assert=>assert_equals( act = lo_ajson->stringify( ) exp = '{"field_data":"field_value"}' ). - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. -class ltcl_to_upper definition final for testing - duration short - risk level harmless. +CLASS ltcl_to_upper DEFINITION FINAL FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. - private section. - methods: - to_json for testing raising z2UI5_cx_ajson_error. -endclass. + PRIVATE SECTION. + METHODS: + to_json FOR TESTING RAISING z2ui5_cx_ajson_error. +ENDCLASS. -class ltcl_to_upper implementation. +CLASS ltcl_to_upper IMPLEMENTATION. - method to_json. + METHOD to_json. - data: - lo_ajson type ref to z2ui5_cl_ajson, - li_mapping type ref to z2ui5_if_ajson_mapping. - data: - begin of ls_result, - field_data type string, - end of ls_result. + DATA: + lo_ajson TYPE REF TO z2ui5_cl_ajson, + li_mapping TYPE REF TO z2ui5_if_ajson_mapping. + DATA: + BEGIN OF ls_result, + field_data TYPE string, + END OF ls_result. li_mapping = z2ui5_cl_ajson_mapping=>create_upper_case( ). @@ -523,13 +531,14 @@ class ltcl_to_upper implementation. lo_ajson = z2ui5_cl_ajson=>create_empty( ii_custom_mapping = li_mapping ). - lo_ajson->set( iv_path = '/' iv_val = ls_result ). + lo_ajson->set( iv_path = '/' + iv_val = ls_result ). cl_abap_unit_assert=>assert_equals( act = lo_ajson->stringify( ) exp = '{"FIELD_DATA":"field_value"}' ). - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. diff --git a/src/01/00/01/z2ui5_cl_ajson_utilities.clas.abap b/src/01/00/01/z2ui5_cl_ajson_utilities.clas.abap index 238b9b19..2f634548 100644 --- a/src/01/00/01/z2ui5_cl_ajson_utilities.clas.abap +++ b/src/01/00/01/z2ui5_cl_ajson_utilities.clas.abap @@ -1,136 +1,136 @@ -class z2ui5_cl_ajson_utilities definition - public - create public . +CLASS z2ui5_cl_ajson_utilities DEFINITION + PUBLIC + CREATE PUBLIC . - public section. + PUBLIC SECTION. - class-methods new - returning - value(ro_instance) type ref to z2ui5_cl_ajson_utilities. - methods diff - importing - !iv_json_a type string optional - !iv_json_b type string optional - !io_json_a type ref to z2ui5_if_ajson optional - !io_json_b type ref to z2ui5_if_ajson optional - !iv_keep_empty_arrays type abap_bool default abap_false - exporting - !eo_insert type ref to z2ui5_if_ajson - !eo_delete type ref to z2ui5_if_ajson - !eo_change type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error . - methods merge - importing - !iv_json_a type string optional - !iv_json_b type string optional - !io_json_a type ref to z2ui5_if_ajson optional - !io_json_b type ref to z2ui5_if_ajson optional - !iv_keep_empty_arrays type abap_bool default abap_false - returning - value(ro_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error . - methods sort - importing - !iv_json type string optional - !io_json type ref to z2ui5_if_ajson optional - returning - value(rv_sorted) type string - raising - z2UI5_cx_ajson_error . - methods is_equal - importing - !iv_json_a type string optional - !iv_json_b type string optional - !ii_json_a type ref to z2ui5_if_ajson optional - !ii_json_b type ref to z2ui5_if_ajson optional - returning - value(rv_yes) type abap_bool - raising - z2UI5_cx_ajson_error . + CLASS-METHODS new + RETURNING + VALUE(ro_instance) TYPE REF TO z2ui5_cl_ajson_utilities. + METHODS diff + IMPORTING + !iv_json_a TYPE string OPTIONAL + !iv_json_b TYPE string OPTIONAL + !io_json_a TYPE REF TO z2ui5_if_ajson OPTIONAL + !io_json_b TYPE REF TO z2ui5_if_ajson OPTIONAL + !iv_keep_empty_arrays TYPE abap_bool DEFAULT abap_false + EXPORTING + !eo_insert TYPE REF TO z2ui5_if_ajson + !eo_delete TYPE REF TO z2ui5_if_ajson + !eo_change TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error . + METHODS merge + IMPORTING + !iv_json_a TYPE string OPTIONAL + !iv_json_b TYPE string OPTIONAL + !io_json_a TYPE REF TO z2ui5_if_ajson OPTIONAL + !io_json_b TYPE REF TO z2ui5_if_ajson OPTIONAL + !iv_keep_empty_arrays TYPE abap_bool DEFAULT abap_false + RETURNING + VALUE(ro_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error . + METHODS sort + IMPORTING + !iv_json TYPE string OPTIONAL + !io_json TYPE REF TO z2ui5_if_ajson OPTIONAL + RETURNING + VALUE(rv_sorted) TYPE string + RAISING + z2ui5_cx_ajson_error . + METHODS is_equal + IMPORTING + !iv_json_a TYPE string OPTIONAL + !iv_json_b TYPE string OPTIONAL + !ii_json_a TYPE REF TO z2ui5_if_ajson OPTIONAL + !ii_json_b TYPE REF TO z2ui5_if_ajson OPTIONAL + RETURNING + VALUE(rv_yes) TYPE abap_bool + RAISING + z2ui5_cx_ajson_error . - protected section. + PROTECTED SECTION. - private section. + PRIVATE SECTION. - data mo_json_a type ref to z2ui5_if_ajson . - data mo_json_b type ref to z2ui5_if_ajson . - data mo_insert type ref to z2ui5_if_ajson . - data mo_delete type ref to z2ui5_if_ajson . - data mo_change type ref to z2ui5_if_ajson . + DATA mo_json_a TYPE REF TO z2ui5_if_ajson . + DATA mo_json_b TYPE REF TO z2ui5_if_ajson . + DATA mo_insert TYPE REF TO z2ui5_if_ajson . + DATA mo_delete TYPE REF TO z2ui5_if_ajson . + DATA mo_change TYPE REF TO z2ui5_if_ajson . - methods normalize_input - importing - !iv_json type string optional - !io_json type ref to z2ui5_if_ajson optional - returning - value(ro_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error . - methods diff_a_b - importing - !iv_path type string - raising - z2UI5_cx_ajson_error . - methods diff_b_a - importing - !iv_path type string - !iv_array type abap_bool default abap_false - raising - z2UI5_cx_ajson_error . - methods delete_empty_nodes - importing - !io_json type ref to z2ui5_if_ajson - !iv_keep_empty_arrays type abap_bool - raising - z2UI5_cx_ajson_error . + METHODS normalize_input + IMPORTING + !iv_json TYPE string OPTIONAL + !io_json TYPE REF TO z2ui5_if_ajson OPTIONAL + RETURNING + VALUE(ro_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error . + METHODS diff_a_b + IMPORTING + !iv_path TYPE string + RAISING + z2ui5_cx_ajson_error . + METHODS diff_b_a + IMPORTING + !iv_path TYPE string + !iv_array TYPE abap_bool DEFAULT abap_false + RAISING + z2ui5_cx_ajson_error . + METHODS delete_empty_nodes + IMPORTING + !io_json TYPE REF TO z2ui5_if_ajson + !iv_keep_empty_arrays TYPE abap_bool + RAISING + z2ui5_cx_ajson_error . ENDCLASS. -CLASS Z2UI5_CL_AJSON_UTILITIES IMPLEMENTATION. +CLASS z2ui5_cl_ajson_utilities IMPLEMENTATION. - method delete_empty_nodes. + METHOD delete_empty_nodes. - data ls_json_tree like line of io_json->mt_json_tree. - data lv_done type abap_bool. + DATA ls_json_tree LIKE LINE OF io_json->mt_json_tree. + DATA lv_done TYPE abap_bool. - do. + DO. lv_done = abap_true. - if iv_keep_empty_arrays = abap_false. - loop at io_json->mt_json_tree into ls_json_tree - where type = z2ui5_if_ajson_types=>node_type-array and children = 0. + IF iv_keep_empty_arrays = abap_false. + LOOP AT io_json->mt_json_tree INTO ls_json_tree + WHERE type = z2ui5_if_ajson_types=>node_type-array AND children = 0. io_json->delete( ls_json_tree-path && ls_json_tree-name ). - endloop. - if sy-subrc = 0. + ENDLOOP. + IF sy-subrc = 0. lv_done = abap_false. - endif. - endif. + ENDIF. + ENDIF. - loop at io_json->mt_json_tree into ls_json_tree - where type = z2ui5_if_ajson_types=>node_type-object and children = 0. + LOOP AT io_json->mt_json_tree INTO ls_json_tree + WHERE type = z2ui5_if_ajson_types=>node_type-object AND children = 0. io_json->delete( ls_json_tree-path && ls_json_tree-name ). - endloop. - if sy-subrc = 0. + ENDLOOP. + IF sy-subrc = 0. lv_done = abap_false. - endif. + ENDIF. - if lv_done = abap_true. - exit. " nothing else to delete - endif. - enddo. + IF lv_done = abap_true. + EXIT. " nothing else to delete + ENDIF. + ENDDO. - endmethod. + ENDMETHOD. - method diff. + METHOD diff. mo_json_a = normalize_input( iv_json = iv_json_a @@ -161,162 +161,162 @@ CLASS Z2UI5_CL_AJSON_UTILITIES IMPLEMENTATION. io_json = eo_change iv_keep_empty_arrays = iv_keep_empty_arrays ). - endmethod. + ENDMETHOD. - method diff_a_b. + METHOD diff_a_b. - data: - lv_path_a type string, - lv_path_b type string. + DATA: + lv_path_a TYPE string, + lv_path_b TYPE string. - field-symbols: - like line of mo_json_a->mt_json_tree, - like line of mo_json_a->mt_json_tree. + FIELD-SYMBOLS: + LIKE LINE OF mo_json_a->mt_json_tree, + LIKE LINE OF mo_json_a->mt_json_tree. - loop at mo_json_a->mt_json_tree assigning where path = iv_path. + LOOP AT mo_json_a->mt_json_tree ASSIGNING WHERE path = iv_path. lv_path_a = -path && -name && '/'. - read table mo_json_b->mt_json_tree assigning - with table key path = -path name = -name. - if sy-subrc = 0. + READ TABLE mo_json_b->mt_json_tree ASSIGNING + WITH TABLE KEY path = -path name = -name. + IF sy-subrc = 0. lv_path_b = -path && -name && '/'. - if -type = -type. - case -type. - when z2ui5_if_ajson_types=>node_type-array. + IF -type = -type. + CASE -type. + WHEN z2ui5_if_ajson_types=>node_type-array. mo_insert->touch_array( lv_path_a ). mo_change->touch_array( lv_path_a ). mo_delete->touch_array( lv_path_a ). diff_a_b( lv_path_a ). - when z2ui5_if_ajson_types=>node_type-object. + WHEN z2ui5_if_ajson_types=>node_type-object. diff_a_b( lv_path_a ). - when others. - if -value <> -value. + WHEN OTHERS. + IF -value <> -value. " save as changed value mo_change->set( iv_path = lv_path_b iv_val = -value iv_node_type = -type ). - endif. - endcase. - else. + ENDIF. + ENDCASE. + ELSE. " save changed type as delete + insert - case -type. - when z2ui5_if_ajson_types=>node_type-array. + CASE -type. + WHEN z2ui5_if_ajson_types=>node_type-array. mo_delete->touch_array( lv_path_a ). diff_a_b( lv_path_a ). - when z2ui5_if_ajson_types=>node_type-object. + WHEN z2ui5_if_ajson_types=>node_type-object. diff_a_b( lv_path_a ). - when others. + WHEN OTHERS. mo_delete->set( iv_path = lv_path_a iv_val = -value iv_node_type = -type ). - endcase. - case -type. - when z2ui5_if_ajson_types=>node_type-array. + ENDCASE. + CASE -type. + WHEN z2ui5_if_ajson_types=>node_type-array. mo_insert->touch_array( lv_path_b ). diff_b_a( lv_path_b ). - when z2ui5_if_ajson_types=>node_type-object. + WHEN z2ui5_if_ajson_types=>node_type-object. diff_b_a( lv_path_b ). - when others. + WHEN OTHERS. mo_insert->set( iv_path = lv_path_b iv_val = -value iv_node_type = -type ). - endcase. - endif. - else. + ENDCASE. + ENDIF. + ELSE. " save as delete - case -type. - when z2ui5_if_ajson_types=>node_type-array. + CASE -type. + WHEN z2ui5_if_ajson_types=>node_type-array. mo_delete->touch_array( lv_path_a ). diff_a_b( lv_path_a ). - when z2ui5_if_ajson_types=>node_type-object. + WHEN z2ui5_if_ajson_types=>node_type-object. diff_a_b( lv_path_a ). - when others. + WHEN OTHERS. mo_delete->set( iv_path = lv_path_a iv_val = -value iv_node_type = -type ). - endcase. - endif. - endloop. + ENDCASE. + ENDIF. + ENDLOOP. - endmethod. + ENDMETHOD. - method diff_b_a. + METHOD diff_b_a. - data lv_path type string. + DATA lv_path TYPE string. - field-symbols like line of mo_json_b->mt_json_tree. + FIELD-SYMBOLS LIKE LINE OF mo_json_b->mt_json_tree. - loop at mo_json_b->mt_json_tree assigning where path = iv_path. + LOOP AT mo_json_b->mt_json_tree ASSIGNING WHERE path = iv_path. lv_path = -path && -name && '/'. - case -type. - when z2ui5_if_ajson_types=>node_type-array. + CASE -type. + WHEN z2ui5_if_ajson_types=>node_type-array. mo_insert->touch_array( lv_path ). diff_b_a( iv_path = lv_path iv_array = abap_true ). - when z2ui5_if_ajson_types=>node_type-object. + WHEN z2ui5_if_ajson_types=>node_type-object. diff_b_a( lv_path ). - when others. - if iv_array = abap_false. - read table mo_json_a->mt_json_tree transporting no fields - with table key path = -path name = -name. - if sy-subrc <> 0. + WHEN OTHERS. + IF iv_array = abap_false. + READ TABLE mo_json_a->mt_json_tree TRANSPORTING NO FIELDS + WITH TABLE KEY path = -path name = -name. + IF sy-subrc <> 0. " save as insert mo_insert->set( iv_path = lv_path iv_val = -value iv_node_type = -type ). - endif. - else. - read table mo_insert->mt_json_tree transporting no fields - with key path = -path value = -value. - if sy-subrc <> 0. + ENDIF. + ELSE. + READ TABLE mo_insert->mt_json_tree TRANSPORTING NO FIELDS + WITH KEY path = -path value = -value. + IF sy-subrc <> 0. " save as new array value mo_insert->push( iv_path = iv_path iv_val = -value ). - endif. - endif. - endcase. - endloop. + ENDIF. + ENDIF. + ENDCASE. + ENDLOOP. - endmethod. + ENDMETHOD. - method is_equal. + METHOD is_equal. - data li_ins type ref to z2ui5_if_ajson. - data li_del type ref to z2ui5_if_ajson. - data li_mod type ref to z2ui5_if_ajson. + DATA li_ins TYPE REF TO z2ui5_if_ajson. + DATA li_del TYPE REF TO z2ui5_if_ajson. + DATA li_mod TYPE REF TO z2ui5_if_ajson. diff( - exporting + EXPORTING iv_json_a = iv_json_a iv_json_b = iv_json_b io_json_a = ii_json_a io_json_b = ii_json_b - importing + IMPORTING eo_insert = li_ins eo_delete = li_del eo_change = li_mod ). rv_yes = boolc( - li_ins->is_empty( ) = abap_true and - li_del->is_empty( ) = abap_true and + li_ins->is_empty( ) = abap_true AND + li_del->is_empty( ) = abap_true AND li_mod->is_empty( ) = abap_true ). - endmethod. + ENDMETHOD. - method merge. + METHOD merge. mo_json_a = normalize_input( iv_json = iv_json_a @@ -338,34 +338,34 @@ CLASS Z2UI5_CL_AJSON_UTILITIES IMPLEMENTATION. io_json = ro_json iv_keep_empty_arrays = iv_keep_empty_arrays ). - endmethod. + ENDMETHOD. - method new. - create object ro_instance. - endmethod. + METHOD new. + CREATE OBJECT ro_instance. + ENDMETHOD. - method normalize_input. + METHOD normalize_input. - if boolc( iv_json is initial ) = boolc( io_json is initial ). - z2UI5_cx_ajson_error=>raise( 'Either supply JSON string or instance, but not both' ). - endif. + IF boolc( iv_json IS INITIAL ) = boolc( io_json IS INITIAL ). + z2ui5_cx_ajson_error=>raise( 'Either supply JSON string or instance, but not both' ). + ENDIF. - if iv_json is not initial. + IF iv_json IS NOT INITIAL. ro_json = z2ui5_cl_ajson=>parse( iv_json ). - elseif io_json is not initial. + ELSEIF io_json IS NOT INITIAL. ro_json = io_json. - else. - z2UI5_cx_ajson_error=>raise( 'Supply either JSON string or instance' ). - endif. + ELSE. + z2ui5_cx_ajson_error=>raise( 'Supply either JSON string or instance' ). + ENDIF. - endmethod. + ENDMETHOD. - method sort. + METHOD sort. - data lo_json type ref to z2ui5_if_ajson. + DATA lo_json TYPE REF TO z2ui5_if_ajson. lo_json = normalize_input( iv_json = iv_json @@ -374,5 +374,5 @@ CLASS Z2UI5_CL_AJSON_UTILITIES IMPLEMENTATION. " Nodes are parsed into a sorted table, so no explicit sorting required rv_sorted = lo_json->stringify( 2 ). - endmethod. + ENDMETHOD. ENDCLASS. diff --git a/src/01/00/01/z2ui5_cl_ajson_utilities.clas.testclasses.abap b/src/01/00/01/z2ui5_cl_ajson_utilities.clas.testclasses.abap index 48ca0c42..1cb053c2 100644 --- a/src/01/00/01/z2ui5_cl_ajson_utilities.clas.testclasses.abap +++ b/src/01/00/01/z2ui5_cl_ajson_utilities.clas.testclasses.abap @@ -2,72 +2,72 @@ * UTIL ********************************************************************** -class lcl_nodes_helper definition final. - public section. +CLASS lcl_nodes_helper DEFINITION FINAL. + PUBLIC SECTION. - data mt_nodes type z2ui5_if_ajson_types=>ty_nodes_tt read-only. + DATA mt_nodes TYPE z2ui5_if_ajson_types=>ty_nodes_tt READ-ONLY. - methods add - importing - iv_str type string. - methods sorted - returning - value(rt_nodes) type z2ui5_if_ajson_types=>ty_nodes_ts. + METHODS add + IMPORTING + iv_str TYPE string. + METHODS sorted + RETURNING + VALUE(rt_nodes) TYPE z2ui5_if_ajson_types=>ty_nodes_ts. -endclass. +ENDCLASS. -class lcl_nodes_helper implementation. - method add. +CLASS lcl_nodes_helper IMPLEMENTATION. + METHOD add. - field-symbols like line of mt_nodes. - data lv_children type string. - data lv_index type string. + FIELD-SYMBOLS LIKE LINE OF mt_nodes. + DATA lv_children TYPE string. + DATA lv_index TYPE string. - append initial line to mt_nodes assigning . + APPEND INITIAL LINE TO mt_nodes ASSIGNING . - split iv_str at '|' into + SPLIT iv_str AT '|' INTO -path -name -type -value lv_index lv_children. - condense -path. - condense -name. - condense -type. - condense -value. + CONDENSE -path. + CONDENSE -name. + CONDENSE -type. + CONDENSE -value. -index = lv_index. -children = lv_children. - endmethod. + ENDMETHOD. - method sorted. + METHOD sorted. rt_nodes = mt_nodes. - endmethod. -endclass. + ENDMETHOD. +ENDCLASS. ********************************************************************** * PARSER ********************************************************************** -class ltcl_parser_test definition final - for testing - risk level harmless - duration short. +CLASS ltcl_parser_test DEFINITION FINAL + FOR TESTING + RISK LEVEL HARMLESS + DURATION SHORT. - public section. + PUBLIC SECTION. - class-methods sample_json - importing - iv_separator type string optional - returning - value(rv_json) type string. + CLASS-METHODS sample_json + IMPORTING + iv_separator TYPE string OPTIONAL + RETURNING + VALUE(rv_json) TYPE string. -endclass. +ENDCLASS. -class ltcl_parser_test implementation. +CLASS ltcl_parser_test IMPLEMENTATION. - method sample_json. + METHOD sample_json. rv_json = '{\n' && @@ -108,46 +108,46 @@ class ltcl_parser_test implementation. ' ]\n' && '}'. - replace all occurrences of '\n' in rv_json with iv_separator. + REPLACE ALL OCCURRENCES OF '\n' IN rv_json WITH iv_separator. - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. ********************************************************************** * JSON UTILITIES ********************************************************************** -class ltcl_json_utils definition - for testing - risk level harmless - duration short - final. +CLASS ltcl_json_utils DEFINITION + FOR TESTING + RISK LEVEL HARMLESS + DURATION SHORT + FINAL. - private section. + PRIVATE SECTION. - methods json_diff for testing raising z2UI5_cx_ajson_error. - methods json_diff_types for testing raising z2UI5_cx_ajson_error. - methods json_diff_arrays for testing raising z2UI5_cx_ajson_error. - methods json_merge for testing raising z2UI5_cx_ajson_error. - methods json_sort for testing raising z2UI5_cx_ajson_error. - methods is_equal for testing raising z2UI5_cx_ajson_error. + METHODS json_diff FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS json_diff_types FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS json_diff_arrays FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS json_merge FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS json_sort FOR TESTING RAISING z2ui5_cx_ajson_error. + METHODS is_equal FOR TESTING RAISING z2ui5_cx_ajson_error. -endclass. +ENDCLASS. -class ltcl_json_utils implementation. +CLASS ltcl_json_utils IMPLEMENTATION. - method json_diff. + METHOD json_diff. - data: - lv_json type string, - lo_util type ref to z2ui5_cl_ajson_utilities, - lo_insert type ref to z2ui5_if_ajson, - lo_delete type ref to z2ui5_if_ajson, - lo_change type ref to z2ui5_if_ajson, - lo_insert_exp type ref to lcl_nodes_helper, - lo_delete_exp type ref to lcl_nodes_helper, - lo_change_exp type ref to lcl_nodes_helper. + DATA: + lv_json TYPE string, + lo_util TYPE REF TO z2ui5_cl_ajson_utilities, + lo_insert TYPE REF TO z2ui5_if_ajson, + lo_delete TYPE REF TO z2ui5_if_ajson, + lo_change TYPE REF TO z2ui5_if_ajson, + lo_insert_exp TYPE REF TO lcl_nodes_helper, + lo_delete_exp TYPE REF TO lcl_nodes_helper, + lo_change_exp TYPE REF TO lcl_nodes_helper. lv_json = '{\n' && @@ -190,9 +190,9 @@ class ltcl_json_utils implementation. ' ]\n' && '}'. - replace all occurrences of '\n' in lv_json with cl_abap_char_utilities=>newline. + REPLACE ALL OCCURRENCES OF '\n' IN lv_json WITH cl_abap_char_utilities=>newline. - create object lo_insert_exp. + CREATE OBJECT lo_insert_exp. lo_insert_exp->add( ' | |object | |0|3' ). lo_insert_exp->add( '/ |boolean |str |true |0|0' ). " changed type (insert new) lo_insert_exp->add( '/ |issues |array | |0|1' ). @@ -201,7 +201,7 @@ class ltcl_json_utils implementation. lo_insert_exp->add( '/issues/1/ |end |object | |0|1' ). lo_insert_exp->add( '/issues/1/end/ |new |num |1 |0|0' ). " array insert - create object lo_delete_exp. + CREATE OBJECT lo_delete_exp. lo_delete_exp->add( ' | |object | |0|3' ). lo_delete_exp->add( '/ |boolean |bool |true |0|0' ). " changed type (delete old) lo_delete_exp->add( '/ |false |bool |false |0|0' ). " delete @@ -210,7 +210,7 @@ class ltcl_json_utils implementation. lo_delete_exp->add( '/issues/1/ |end |object | |0|1' ). lo_delete_exp->add( '/issues/1/end/ |row |num |4 |0|0' ). " array delete - create object lo_change_exp. + CREATE OBJECT lo_change_exp. lo_change_exp->add( ' | |object | |0|2' ). lo_change_exp->add( '/ |issues |array | |0|1' ). lo_change_exp->add( '/ |number |num |789 |0|0' ). " changed value @@ -218,13 +218,13 @@ class ltcl_json_utils implementation. lo_change_exp->add( '/issues/1/ |start |object | |0|1' ). lo_change_exp->add( '/issues/1/start/|row |num |5 |0|0' ). " array change - create object lo_util. + CREATE OBJECT lo_util. lo_util->diff( - exporting + EXPORTING iv_json_a = ltcl_parser_test=>sample_json( ) iv_json_b = lv_json - importing + IMPORTING eo_insert = lo_insert eo_delete = lo_delete eo_change = lo_change ). @@ -241,19 +241,19 @@ class ltcl_json_utils implementation. act = lo_change->mt_json_tree exp = lo_change_exp->mt_nodes ). - endmethod. + ENDMETHOD. - method json_diff_types. + METHOD json_diff_types. - data: - lv_json_a type string, - lv_json_b type string, - lo_util type ref to z2ui5_cl_ajson_utilities, - lo_insert type ref to z2ui5_if_ajson, - lo_delete type ref to z2ui5_if_ajson, - lo_change type ref to z2ui5_if_ajson, - lo_insert_exp type ref to lcl_nodes_helper, - lo_delete_exp type ref to lcl_nodes_helper. + DATA: + lv_json_a TYPE string, + lv_json_b TYPE string, + lo_util TYPE REF TO z2ui5_cl_ajson_utilities, + lo_insert TYPE REF TO z2ui5_if_ajson, + lo_delete TYPE REF TO z2ui5_if_ajson, + lo_change TYPE REF TO z2ui5_if_ajson, + lo_insert_exp TYPE REF TO lcl_nodes_helper, + lo_delete_exp TYPE REF TO lcl_nodes_helper. " Change single value to array lv_json_a = @@ -272,27 +272,27 @@ class ltcl_json_utils implementation. ' "number": 123\n' && '}'. - replace all occurrences of '\n' in lv_json_a with cl_abap_char_utilities=>newline. - replace all occurrences of '\n' in lv_json_b with cl_abap_char_utilities=>newline. + REPLACE ALL OCCURRENCES OF '\n' IN lv_json_a WITH cl_abap_char_utilities=>newline. + REPLACE ALL OCCURRENCES OF '\n' IN lv_json_b WITH cl_abap_char_utilities=>newline. - create object lo_insert_exp. + CREATE OBJECT lo_insert_exp. lo_insert_exp->add( ' | |object | |0|1' ). lo_insert_exp->add( '/ |string |array | |0|3' ). lo_insert_exp->add( '/string/ |1 |str |a |1|0' ). lo_insert_exp->add( '/string/ |2 |str |b |2|0' ). lo_insert_exp->add( '/string/ |3 |str |c |3|0' ). - create object lo_delete_exp. + CREATE OBJECT lo_delete_exp. lo_delete_exp->add( ' | |object | |0|1' ). lo_delete_exp->add( '/ |string |str |abc |0|0' ). - create object lo_util. + CREATE OBJECT lo_util. lo_util->diff( - exporting + EXPORTING iv_json_a = lv_json_a iv_json_b = lv_json_b - importing + IMPORTING eo_insert = lo_insert eo_delete = lo_delete eo_change = lo_change ). @@ -311,10 +311,10 @@ class ltcl_json_utils implementation. " Change array to single value lo_util->diff( - exporting + EXPORTING iv_json_a = lv_json_b iv_json_b = lv_json_a - importing + IMPORTING eo_insert = lo_insert eo_delete = lo_delete eo_change = lo_change ). @@ -331,18 +331,18 @@ class ltcl_json_utils implementation. act = lines( lo_change->mt_json_tree ) exp = 0 ). - endmethod. + ENDMETHOD. - method json_diff_arrays. + METHOD json_diff_arrays. - data: - lv_json_a type string, - lv_json_b type string, - lo_util type ref to z2ui5_cl_ajson_utilities, - lo_insert type ref to z2ui5_if_ajson, - lo_delete type ref to z2ui5_if_ajson, - lo_change type ref to z2ui5_if_ajson, - lo_insert_exp type ref to lcl_nodes_helper. + DATA: + lv_json_a TYPE string, + lv_json_b TYPE string, + lo_util TYPE REF TO z2ui5_cl_ajson_utilities, + lo_insert TYPE REF TO z2ui5_if_ajson, + lo_delete TYPE REF TO z2ui5_if_ajson, + lo_change TYPE REF TO z2ui5_if_ajson, + lo_insert_exp TYPE REF TO lcl_nodes_helper. " Add empty array lv_json_a = @@ -356,17 +356,17 @@ class ltcl_json_utils implementation. ' "number": 123\n' && '}'. - replace all occurrences of '\n' in lv_json_a with cl_abap_char_utilities=>newline. - replace all occurrences of '\n' in lv_json_b with cl_abap_char_utilities=>newline. + REPLACE ALL OCCURRENCES OF '\n' IN lv_json_a WITH cl_abap_char_utilities=>newline. + REPLACE ALL OCCURRENCES OF '\n' IN lv_json_b WITH cl_abap_char_utilities=>newline. - create object lo_util. + CREATE OBJECT lo_util. " Empty arrays are ignored by default lo_util->diff( - exporting + EXPORTING iv_json_a = lv_json_a iv_json_b = lv_json_b - importing + IMPORTING eo_insert = lo_insert eo_delete = lo_delete eo_change = lo_change ). @@ -385,16 +385,16 @@ class ltcl_json_utils implementation. " Keep empty arrays lo_util->diff( - exporting + EXPORTING iv_json_a = lv_json_a iv_json_b = lv_json_b iv_keep_empty_arrays = abap_true - importing + IMPORTING eo_insert = lo_insert eo_delete = lo_delete eo_change = lo_change ). - create object lo_insert_exp. + CREATE OBJECT lo_insert_exp. lo_insert_exp->add( ' | |object | |0|1' ). lo_insert_exp->add( '/ |names |array | |0|0' ). @@ -410,16 +410,16 @@ class ltcl_json_utils implementation. act = lines( lo_change->mt_json_tree ) exp = 0 ). - endmethod. + ENDMETHOD. - method json_merge. + METHOD json_merge. - data: - lv_json_a type string, - lv_json_b type string, - lo_util type ref to z2ui5_cl_ajson_utilities, - lo_merge type ref to z2ui5_if_ajson, - lo_merge_exp type ref to lcl_nodes_helper. + DATA: + lv_json_a TYPE string, + lv_json_b TYPE string, + lo_util TYPE REF TO z2ui5_cl_ajson_utilities, + lo_merge TYPE REF TO z2ui5_if_ajson, + lo_merge_exp TYPE REF TO lcl_nodes_helper. " Merge new value of b into a lv_json_a = @@ -441,10 +441,10 @@ class ltcl_json_utils implementation. ' "float": 123.45\n' && '}'. - replace all occurrences of '\n' in lv_json_a with cl_abap_char_utilities=>newline. - replace all occurrences of '\n' in lv_json_b with cl_abap_char_utilities=>newline. + REPLACE ALL OCCURRENCES OF '\n' IN lv_json_a WITH cl_abap_char_utilities=>newline. + REPLACE ALL OCCURRENCES OF '\n' IN lv_json_b WITH cl_abap_char_utilities=>newline. - create object lo_merge_exp. + CREATE OBJECT lo_merge_exp. lo_merge_exp->add( ' | |object | |0|3' ). lo_merge_exp->add( '/ |float |num |123.45 |0|0' ). lo_merge_exp->add( '/ |number |num |123 |0|0' ). @@ -453,7 +453,7 @@ class ltcl_json_utils implementation. lo_merge_exp->add( '/string/ |2 |str |c |2|0' ). lo_merge_exp->add( '/string/ |3 |str |b |3|0' ). - create object lo_util. + CREATE OBJECT lo_util. lo_merge = lo_util->merge( iv_json_a = lv_json_a @@ -463,15 +463,15 @@ class ltcl_json_utils implementation. act = lo_merge->mt_json_tree exp = lo_merge_exp->mt_nodes ). - endmethod. + ENDMETHOD. - method json_sort. + METHOD json_sort. - data: - lv_json type string, - lo_util type ref to z2ui5_cl_ajson_utilities, - lv_sorted type string, - lv_sorted_exp type string. + DATA: + lv_json TYPE string, + lo_util TYPE REF TO z2ui5_cl_ajson_utilities, + lv_sorted TYPE string, + lv_sorted_exp TYPE string. lv_json = '{\n' && @@ -485,7 +485,7 @@ class ltcl_json_utils implementation. ' "date": "2020-03-15"\n' && '}'. - replace all occurrences of '\n' in lv_json with cl_abap_char_utilities=>newline. + REPLACE ALL OCCURRENCES OF '\n' IN lv_json WITH cl_abap_char_utilities=>newline. lv_sorted_exp = '{\n' && @@ -499,9 +499,9 @@ class ltcl_json_utils implementation. ' "true": true\n' && '}'. - replace all occurrences of '\n' in lv_sorted_exp with cl_abap_char_utilities=>newline. + REPLACE ALL OCCURRENCES OF '\n' IN lv_sorted_exp WITH cl_abap_char_utilities=>newline. - create object lo_util. + CREATE OBJECT lo_util. lv_sorted = lo_util->sort( iv_json = lv_json ). @@ -509,9 +509,9 @@ class ltcl_json_utils implementation. act = lv_sorted exp = lv_sorted_exp ). - endmethod. + ENDMETHOD. - method is_equal. + METHOD is_equal. cl_abap_unit_assert=>assert_equals( act = z2ui5_cl_ajson_utilities=>new( )->is_equal( @@ -543,6 +543,6 @@ class ltcl_json_utils implementation. iv_json_b = '{"a":1,"b":2}' ) exp = abap_false ). - endmethod. + ENDMETHOD. -endclass. +ENDCLASS. diff --git a/src/01/00/01/z2ui5_cx_ajson_error.clas.abap b/src/01/00/01/z2ui5_cx_ajson_error.clas.abap index 0180dfa3..2effdd0a 100644 --- a/src/01/00/01/z2ui5_cx_ajson_error.clas.abap +++ b/src/01/00/01/z2ui5_cx_ajson_error.clas.abap @@ -1,4 +1,4 @@ -class Z2UI5_CX_AJSON_ERROR definition +class z2ui5_cx_ajson_error definition public inheriting from CX_STATIC_CHECK final @@ -45,7 +45,7 @@ public section. !IV_LOCATION type STRING optional !IS_NODE type ANY optional raising - Z2UI5_CX_AJSON_ERROR . + z2ui5_cx_ajson_error . methods SET_LOCATION importing !IV_LOCATION type STRING optional @@ -64,10 +64,10 @@ ENDCLASS. -CLASS Z2UI5_CX_AJSON_ERROR IMPLEMENTATION. +CLASS z2ui5_cx_ajson_error IMPLEMENTATION. -method CONSTRUCTOR ##ADT_SUPPRESS_GENERATION. +method CONSTRUCTOR. CALL METHOD SUPER->CONSTRUCTOR EXPORTING PREVIOUS = PREVIOUS diff --git a/src/01/00/01/z2ui5_cx_ajson_error.clas.testclasses.abap b/src/01/00/01/z2ui5_cx_ajson_error.clas.testclasses.abap index 919589fd..b5bf9d62 100644 --- a/src/01/00/01/z2ui5_cx_ajson_error.clas.testclasses.abap +++ b/src/01/00/01/z2ui5_cx_ajson_error.clas.testclasses.abap @@ -20,7 +20,9 @@ class ltcl_error implementation. data lx type ref to z2ui5_cx_ajson_error. data lv_msg type string. - lv_msg = repeat( val = 'a' occ = 50 ) && repeat( val = 'b' occ = 50 ) && '123'. + lv_msg = repeat( val = 'a' + occ = 50 ) && repeat( val = 'b' + occ = 50 ) && '123'. try. z2ui5_cx_ajson_error=>raise( lv_msg ). @@ -38,7 +40,8 @@ class ltcl_error implementation. data lx type ref to z2ui5_cx_ajson_error. try. - z2ui5_cx_ajson_error=>raise( iv_msg = 'a' iv_location = 'b' ). + z2ui5_cx_ajson_error=>raise( iv_msg = 'a' + iv_location = 'b' ). cl_abap_unit_assert=>fail( ). catch z2ui5_cx_ajson_error into lx. cl_abap_unit_assert=>assert_equals( @@ -57,7 +60,8 @@ class ltcl_error implementation. ls_node-name = 'y'. try. - z2ui5_cx_ajson_error=>raise( iv_msg = 'a' is_node = ls_node ). + z2ui5_cx_ajson_error=>raise( iv_msg = 'a' + is_node = ls_node ). cl_abap_unit_assert=>fail( ). catch z2ui5_cx_ajson_error into lx. cl_abap_unit_assert=>assert_equals( @@ -72,7 +76,8 @@ class ltcl_error implementation. data lx type ref to z2ui5_cx_ajson_error. try. - z2ui5_cx_ajson_error=>raise( iv_msg = 'a' iv_location = 'b' ). + z2ui5_cx_ajson_error=>raise( iv_msg = 'a' + iv_location = 'b' ). cl_abap_unit_assert=>fail( ). catch z2ui5_cx_ajson_error into lx. cl_abap_unit_assert=>assert_equals( diff --git a/src/01/00/01/z2ui5_if_ajson.intf.abap b/src/01/00/01/z2ui5_if_ajson.intf.abap index c0f44945..a9df01b5 100644 --- a/src/01/00/01/z2ui5_if_ajson.intf.abap +++ b/src/01/00/01/z2ui5_if_ajson.intf.abap @@ -1,262 +1,262 @@ -interface z2ui5_if_ajson - public. +INTERFACE z2ui5_if_ajson + PUBLIC. - constants version type string value 'v1.1.9'. "#EC NOTEXT - constants origin type string value 'https://github.com/sbcgua/ajson'. "#EC NOTEXT - constants license type string value 'MIT'. "#EC NOTEXT + CONSTANTS version TYPE string VALUE 'v1.1.10'. "#EC NOTEXT + CONSTANTS origin TYPE string VALUE 'https://github.com/sbcgua/ajson'. "#EC NOTEXT + CONSTANTS license TYPE string VALUE 'MIT'. "#EC NOTEXT - types: - begin of ty_opts, - read_only type abap_bool, - keep_item_order type abap_bool, - format_datetime type abap_bool, - to_abap_corresponding_only type abap_bool, - end of ty_opts. + TYPES: + BEGIN OF ty_opts, + read_only TYPE abap_bool, + keep_item_order TYPE abap_bool, + format_datetime TYPE abap_bool, + to_abap_corresponding_only TYPE abap_bool, + END OF ty_opts. " DATA - data mt_json_tree type z2ui5_if_ajson_types=>ty_nodes_ts read-only. + DATA mt_json_tree TYPE z2ui5_if_ajson_types=>ty_nodes_ts READ-ONLY. " CLONING - methods clone - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. - methods filter - importing - ii_filter type ref to z2ui5_if_ajson_filter - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. - methods map - importing - ii_mapper type ref to z2ui5_if_ajson_mapping - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS clone + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. + METHODS filter + IMPORTING + ii_filter TYPE REF TO z2ui5_if_ajson_filter + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. + METHODS map + IMPORTING + ii_mapper TYPE REF TO z2ui5_if_ajson_mapping + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. " METHODS - methods freeze. - methods keep_item_order - returning - value(ri_json) type ref to z2ui5_if_ajson. - methods format_datetime - importing - iv_use_iso type abap_bool default abap_true - returning - value(ri_json) type ref to z2ui5_if_ajson. - methods to_abap_corresponding_only - importing - iv_enable type abap_bool default abap_true - returning - value(ri_json) type ref to z2ui5_if_ajson. - methods opts - returning - value(rs_opts) type ty_opts. + METHODS freeze. + METHODS keep_item_order + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson. + METHODS format_datetime + IMPORTING + iv_use_iso TYPE abap_bool DEFAULT abap_true + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson. + METHODS to_abap_corresponding_only + IMPORTING + iv_enable TYPE abap_bool DEFAULT abap_true + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson. + METHODS opts + RETURNING + VALUE(rs_opts) TYPE ty_opts. " METHODS ex.reader - methods is_empty - returning - value(rv_yes) type abap_bool. + METHODS is_empty + RETURNING + VALUE(rv_yes) TYPE abap_bool. - methods exists - importing - iv_path type string - returning - value(rv_exists) type abap_bool. + METHODS exists + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_exists) TYPE abap_bool. - methods members - importing - iv_path type string - returning - value(rt_members) type string_table. + METHODS members + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rt_members) TYPE string_table. - methods get - importing - iv_path type string - returning - value(rv_value) type string. + METHODS get + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_value) TYPE string. - methods get_node_type - importing - iv_path type string - returning - value(rv_node_type) type z2ui5_if_ajson_types=>ty_node_type. + METHODS get_node_type + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_node_type) TYPE z2ui5_if_ajson_types=>ty_node_type. - methods get_boolean - importing - iv_path type string - returning - value(rv_value) type abap_bool. + METHODS get_boolean + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_value) TYPE abap_bool. - methods get_integer - importing - iv_path type string - returning - value(rv_value) type i. + METHODS get_integer + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_value) TYPE i. - methods get_number - importing - iv_path type string - returning - value(rv_value) type f. + METHODS get_number + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_value) TYPE f. - methods get_date - importing - iv_path type string - returning - value(rv_value) type d. + METHODS get_date + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_value) TYPE d. - methods get_timestamp - importing - iv_path type string - returning - value(rv_value) type timestamp. + METHODS get_timestamp + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_value) TYPE timestamp. - methods get_string - importing - iv_path type string - returning - value(rv_value) type string. + METHODS get_string + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rv_value) TYPE string. - methods slice - importing - iv_path type string - returning - value(ri_json) type ref to z2ui5_if_ajson. + METHODS slice + IMPORTING + iv_path TYPE string + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson. - methods to_abap - importing - iv_corresponding type abap_bool default abap_false - exporting - ev_container type any - raising - z2UI5_cx_ajson_error. + METHODS to_abap + IMPORTING + iv_corresponding TYPE abap_bool DEFAULT abap_false + EXPORTING + ev_container TYPE any + RAISING + z2ui5_cx_ajson_error. - methods array_to_string_table - importing - iv_path type string - returning - value(rt_string_table) type string_table - raising - z2UI5_cx_ajson_error. + METHODS array_to_string_table + IMPORTING + iv_path TYPE string + RETURNING + VALUE(rt_string_table) TYPE string_table + RAISING + z2ui5_cx_ajson_error. " METHODS ex.writer - methods clear - raising - z2UI5_cx_ajson_error. + METHODS clear + RAISING + z2ui5_cx_ajson_error. - methods set - importing - iv_path type string - iv_val type any - iv_ignore_empty type abap_bool default abap_true - iv_node_type type z2ui5_if_ajson_types=>ty_node_type optional - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS set + IMPORTING + iv_path TYPE string + iv_val TYPE any + iv_ignore_empty TYPE abap_bool DEFAULT abap_true + iv_node_type TYPE z2ui5_if_ajson_types=>ty_node_type OPTIONAL + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods setx - importing - iv_param type string - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS setx + IMPORTING + iv_param TYPE string + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods set_boolean - importing - iv_path type string - iv_val type any - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS set_boolean + IMPORTING + iv_path TYPE string + iv_val TYPE any + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods set_string - importing - iv_path type string - iv_val type clike - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS set_string + IMPORTING + iv_path TYPE string + iv_val TYPE clike + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods set_integer - importing - iv_path type string - iv_val type i - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS set_integer + IMPORTING + iv_path TYPE string + iv_val TYPE i + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods set_date - importing - iv_path type string - iv_val type d - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS set_date + IMPORTING + iv_path TYPE string + iv_val TYPE d + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods set_timestamp - importing - iv_path type string - iv_val type timestamp - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS set_timestamp + IMPORTING + iv_path TYPE string + iv_val TYPE timestamp + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods set_null - importing - iv_path type string - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS set_null + IMPORTING + iv_path TYPE string + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods delete - importing - iv_path type string - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS delete + IMPORTING + iv_path TYPE string + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods touch_array - importing - iv_path type string - iv_clear type abap_bool default abap_false - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS touch_array + IMPORTING + iv_path TYPE string + iv_clear TYPE abap_bool DEFAULT abap_false + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods push - importing - iv_path type string - iv_val type any - returning - value(ri_json) type ref to z2ui5_if_ajson - raising - z2UI5_cx_ajson_error. + METHODS push + IMPORTING + iv_path TYPE string + iv_val TYPE any + RETURNING + VALUE(ri_json) TYPE REF TO z2ui5_if_ajson + RAISING + z2ui5_cx_ajson_error. - methods stringify - importing - iv_indent type i default 0 - returning - value(rv_json) type string - raising - z2UI5_cx_ajson_error. + METHODS stringify + IMPORTING + iv_indent TYPE i DEFAULT 0 + RETURNING + VALUE(rv_json) TYPE string + RAISING + z2ui5_cx_ajson_error. -endinterface. +ENDINTERFACE. diff --git a/src/01/00/01/z2ui5_if_ajson_filter.intf.abap b/src/01/00/01/z2ui5_if_ajson_filter.intf.abap index e8c61e3c..5a89d755 100644 --- a/src/01/00/01/z2ui5_if_ajson_filter.intf.abap +++ b/src/01/00/01/z2ui5_if_ajson_filter.intf.abap @@ -1,23 +1,23 @@ -interface z2ui5_if_ajson_filter - public. +INTERFACE z2ui5_if_ajson_filter + PUBLIC. - types ty_filter_tab TYPE STANDARD TABLE OF ref to z2ui5_if_ajson_filter with key table_line. - types ty_visit_type type i. + TYPES ty_filter_tab TYPE STANDARD TABLE OF REF TO z2ui5_if_ajson_filter WITH KEY table_line. + TYPES ty_visit_type TYPE i. - constants: - begin of visit_type, - value type ty_visit_type value 0, - open type ty_visit_type value 1, - close type ty_visit_type value 2, - end of visit_type. + CONSTANTS: + BEGIN OF visit_type, + value TYPE ty_visit_type VALUE 0, + open TYPE ty_visit_type VALUE 1, + close TYPE ty_visit_type VALUE 2, + END OF visit_type. - methods keep_node - importing - is_node type z2ui5_if_ajson_types=>ty_node - iv_visit type ty_visit_type default visit_type-value - returning - value(rv_keep) type abap_bool - raising - z2UI5_cx_ajson_error. + METHODS keep_node + IMPORTING + is_node TYPE z2ui5_if_ajson_types=>ty_node + iv_visit TYPE ty_visit_type DEFAULT visit_type-value + RETURNING + VALUE(rv_keep) TYPE abap_bool + RAISING + z2ui5_cx_ajson_error. -endinterface. +ENDINTERFACE. diff --git a/src/01/00/01/z2ui5_if_ajson_mapping.intf.abap b/src/01/00/01/z2ui5_if_ajson_mapping.intf.abap index bfc18ab5..d1566936 100644 --- a/src/01/00/01/z2ui5_if_ajson_mapping.intf.abap +++ b/src/01/00/01/z2ui5_if_ajson_mapping.intf.abap @@ -1,8 +1,6 @@ INTERFACE z2ui5_if_ajson_mapping PUBLIC. - INTERFACES if_serializable_object. - TYPES: BEGIN OF ty_mapping_field, " deprecated, will be removed abap TYPE string, @@ -15,7 +13,7 @@ INTERFACE z2ui5_if_ajson_mapping TYPES: BEGIN OF ty_rename, from TYPE string, - to TYPE string, + to TYPE string, END OF ty_rename, tty_rename_map TYPE STANDARD TABLE OF ty_rename WITH UNIQUE SORTED KEY by_name COMPONENTS from. diff --git a/src/01/00/01/z2ui5_if_ajson_types.intf.abap b/src/01/00/01/z2ui5_if_ajson_types.intf.abap index c8d0ce4f..04a959bb 100644 --- a/src/01/00/01/z2ui5_if_ajson_types.intf.abap +++ b/src/01/00/01/z2ui5_if_ajson_types.intf.abap @@ -1,41 +1,41 @@ -interface z2ui5_if_ajson_types - public. +INTERFACE z2ui5_if_ajson_types + PUBLIC. - types: - ty_node_type type string. + TYPES: + ty_node_type TYPE string. - constants: - begin of node_type, - boolean type ty_node_type value 'bool', - string type ty_node_type value 'str', - number type ty_node_type value 'num', - null type ty_node_type value 'null', - array type ty_node_type value 'array', - object type ty_node_type value 'object', - end of node_type. + CONSTANTS: + BEGIN OF node_type, + boolean TYPE ty_node_type VALUE 'bool', + string TYPE ty_node_type VALUE 'str', + number TYPE ty_node_type VALUE 'num', + null TYPE ty_node_type VALUE 'null', + array TYPE ty_node_type VALUE 'array', + object TYPE ty_node_type VALUE 'object', + END OF node_type. - types: - begin of ty_node, - path type string, - name type string, - type type ty_node_type, - value type string, - index type i, - order type i, - children type i, - end of ty_node. - types: - ty_nodes_tt TYPE STANDARD TABLE OF ty_node with key path name. - types: - ty_nodes_ts type sorted table of ty_node - with unique key path name - with non-unique sorted key array_index components path index - with non-unique sorted key item_order components path order. + TYPES: + BEGIN OF ty_node, + path TYPE string, + name TYPE string, + type TYPE ty_node_type, + value TYPE string, + index TYPE i, + order TYPE i, + children TYPE i, + END OF ty_node. + TYPES: + ty_nodes_tt TYPE STANDARD TABLE OF ty_node WITH KEY path name. + TYPES: + ty_nodes_ts TYPE SORTED TABLE OF ty_node + WITH UNIQUE KEY path name + WITH NON-UNIQUE SORTED KEY array_index COMPONENTS path index + WITH NON-UNIQUE SORTED KEY item_order COMPONENTS path order. - types: - begin of ty_path_name, - path type string, - name type string, - end of ty_path_name. + TYPES: + BEGIN OF ty_path_name, + path TYPE string, + name TYPE string, + END OF ty_path_name. -endinterface. +ENDINTERFACE.