update ajson mirror (#1379)

This commit is contained in:
oblomov-dev 2024-09-07 12:56:21 +02:00 committed by GitHub
parent 8d9efe5409
commit 860f03d05e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 2575 additions and 2087 deletions

43
.github/workflows/ajson_mirror.yaml vendored Normal file
View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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 <n> 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 = <n>
is_parent_type = is_parent_type ).
is_node = <n>
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 <parent_stdtab> REFERENCE INTO lr_target_field.
ASSERT sy-subrc = 0.
ELSE.
CLEAR <tab_item>.
ENDIF.
WHEN lif_kind=>struct_flat OR lif_kind=>struct_deep.
@ -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 <n>-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 = <n>-path && <n>-name && '/'
is_parent_type = ls_node_type
i_container_ref = lr_target_field ).
iv_path = <n>-path && <n>-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 = <n>-path && <n>-name && '/'
is_parent_type = ls_node_type
i_container_ref = lr_target_field ).
iv_path = <n>-path && <n>-name && '/'
is_parent_type = ls_node_type
i_container_ref = lr_target_field ).
WHEN OTHERS.
value_to_abap(
is_node = <n>
is_node_type = ls_node_type
i_container_ref = lr_target_field ).
is_node = <n>
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 = <n>-path && <n>-name ).
iv_msg = 'Source is not a number'
iv_location = <n>-path && <n>-name ).
CATCH cx_root INTO lx_root.
z2ui5_cx_ajson_error=>raise(
iv_msg = lx_root->get_text( )
iv_location = <n>-path && <n>-name ).
iv_msg = lx_root->get_text( )
iv_location = <n>-path && <n>-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.

View File

@ -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 <s> LIKE LINE OF lt_tab.
APPEND INITIAL LINE TO lt_tab ASSIGNING <s>.
@ -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.

View File

@ -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.

View File

@ -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 <p> like line of mt_skip_paths.
DATA lv_full_path TYPE string.
FIELD-SYMBOLS <p> 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 <p>.
if lv_full_path cp <p>.
LOOP AT mt_skip_paths ASSIGNING <p>.
IF lv_full_path CP <p>.
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 <s> type string.
DATA lv_s TYPE string.
DATA lt_tab TYPE string_table.
FIELD-SYMBOLS <s> 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 <s>.
if <s> 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 <s>.
IF <s> IS INITIAL.
DELETE lt_tab INDEX sy-tabix.
CONTINUE.
ENDIF.
<s> = condense( to_lower( <s> ) ).
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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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 <r> like line of mt_rename_map.
DATA lv_full_path TYPE string.
DATA lv_pair_found TYPE abap_bool.
FIELD-SYMBOLS <r> 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 <r> 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 <r> 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 <r> with table key by_name components from = lv_full_path.
READ TABLE mt_rename_map ASSIGNING <r> 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 <r>.
if lv_full_path cp <r>-from.
LOOP AT mt_rename_map ASSIGNING <r>.
IF lv_full_path CP <r>-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 = <r>-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 <token> 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 <token> 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 <token> from lv_from.
translate <token>(1) to upper case.
endloop.
SPLIT rv_result AT `_` INTO TABLE lt_tokens.
LOOP AT lt_tokens ASSIGNING <token> FROM lv_from.
TRANSLATE <token>(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 <token> like line of lt_tokens.
DATA lt_tokens TYPE STANDARD TABLE OF lty_token.
DATA lv_from TYPE i.
FIELD-SYMBOLS <token> 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 <token> from lv_from.
translate <token>+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 <token> FROM lv_from.
TRANSLATE <token>+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.

View File

@ -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 <i> like line of lt_map.
DATA lt_map TYPE z2ui5_if_ajson_mapping=>tty_rename_map.
FIELD-SYMBOLS <i> LIKE LINE OF lt_map.
append initial line to lt_map assigning <i>.
APPEND INITIAL LINE TO lt_map ASSIGNING <i>.
<i>-from = 'a'.
<i>-to = 'x'.
append initial line to lt_map assigning <i>.
APPEND INITIAL LINE TO lt_map ASSIGNING <i>.
<i>-from = 'c'.
<i>-to = 'y'.
append initial line to lt_map assigning <i>.
APPEND INITIAL LINE TO lt_map ASSIGNING <i>.
<i>-from = 'd'.
<i>-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 <i> like line of lt_map.
DATA lt_map TYPE z2ui5_if_ajson_mapping=>tty_rename_map.
FIELD-SYMBOLS <i> LIKE LINE OF lt_map.
append initial line to lt_map assigning <i>.
APPEND INITIAL LINE TO lt_map ASSIGNING <i>.
<i>-from = '/b/a'.
<i>-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 <i> like line of lt_map.
DATA lt_map TYPE z2ui5_if_ajson_mapping=>tty_rename_map.
FIELD-SYMBOLS <i> LIKE LINE OF lt_map.
append initial line to lt_map assigning <i>.
APPEND INITIAL LINE TO lt_map ASSIGNING <i>.
<i>-from = '/*/this*'.
<i>-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 <i> like line of lt_map.
DATA lt_map TYPE z2ui5_if_ajson_mapping=>tty_rename_map.
FIELD-SYMBOLS <i> LIKE LINE OF lt_map.
append initial line to lt_map assigning <i>.
APPEND INITIAL LINE TO lt_map ASSIGNING <i>.
<i>-from = '/b/a'.
<i>-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.

View File

@ -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:
<node_a> like line of mo_json_a->mt_json_tree,
<node_b> like line of mo_json_a->mt_json_tree.
FIELD-SYMBOLS:
<node_a> LIKE LINE OF mo_json_a->mt_json_tree,
<node_b> LIKE LINE OF mo_json_a->mt_json_tree.
loop at mo_json_a->mt_json_tree assigning <node_a> where path = iv_path.
LOOP AT mo_json_a->mt_json_tree ASSIGNING <node_a> WHERE path = iv_path.
lv_path_a = <node_a>-path && <node_a>-name && '/'.
read table mo_json_b->mt_json_tree assigning <node_b>
with table key path = <node_a>-path name = <node_a>-name.
if sy-subrc = 0.
READ TABLE mo_json_b->mt_json_tree ASSIGNING <node_b>
WITH TABLE KEY path = <node_a>-path name = <node_a>-name.
IF sy-subrc = 0.
lv_path_b = <node_b>-path && <node_b>-name && '/'.
if <node_a>-type = <node_b>-type.
case <node_a>-type.
when z2ui5_if_ajson_types=>node_type-array.
IF <node_a>-type = <node_b>-type.
CASE <node_a>-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 <node_a>-value <> <node_b>-value.
WHEN OTHERS.
IF <node_a>-value <> <node_b>-value.
" save as changed value
mo_change->set(
iv_path = lv_path_b
iv_val = <node_b>-value
iv_node_type = <node_b>-type ).
endif.
endcase.
else.
ENDIF.
ENDCASE.
ELSE.
" save changed type as delete + insert
case <node_a>-type.
when z2ui5_if_ajson_types=>node_type-array.
CASE <node_a>-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 = <node_a>-value
iv_node_type = <node_a>-type ).
endcase.
case <node_b>-type.
when z2ui5_if_ajson_types=>node_type-array.
ENDCASE.
CASE <node_b>-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 = <node_b>-value
iv_node_type = <node_b>-type ).
endcase.
endif.
else.
ENDCASE.
ENDIF.
ELSE.
" save as delete
case <node_a>-type.
when z2ui5_if_ajson_types=>node_type-array.
CASE <node_a>-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 = <node_a>-value
iv_node_type = <node_a>-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 <node_b> like line of mo_json_b->mt_json_tree.
FIELD-SYMBOLS <node_b> LIKE LINE OF mo_json_b->mt_json_tree.
loop at mo_json_b->mt_json_tree assigning <node_b> where path = iv_path.
LOOP AT mo_json_b->mt_json_tree ASSIGNING <node_b> WHERE path = iv_path.
lv_path = <node_b>-path && <node_b>-name && '/'.
case <node_b>-type.
when z2ui5_if_ajson_types=>node_type-array.
CASE <node_b>-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 = <node_b>-path name = <node_b>-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 = <node_b>-path name = <node_b>-name.
IF sy-subrc <> 0.
" save as insert
mo_insert->set(
iv_path = lv_path
iv_val = <node_b>-value
iv_node_type = <node_b>-type ).
endif.
else.
read table mo_insert->mt_json_tree transporting no fields
with key path = <node_b>-path value = <node_b>-value.
if sy-subrc <> 0.
ENDIF.
ELSE.
READ TABLE mo_insert->mt_json_tree TRANSPORTING NO FIELDS
WITH KEY path = <node_b>-path value = <node_b>-value.
IF sy-subrc <> 0.
" save as new array value
mo_insert->push(
iv_path = iv_path
iv_val = <node_b>-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.

View File

@ -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 <n> like line of mt_nodes.
data lv_children type string.
data lv_index type string.
FIELD-SYMBOLS <n> LIKE LINE OF mt_nodes.
DATA lv_children TYPE string.
DATA lv_index TYPE string.
append initial line to mt_nodes assigning <n>.
APPEND INITIAL LINE TO mt_nodes ASSIGNING <n>.
split iv_str at '|' into
SPLIT iv_str AT '|' INTO
<n>-path
<n>-name
<n>-type
<n>-value
lv_index
lv_children.
condense <n>-path.
condense <n>-name.
condense <n>-type.
condense <n>-value.
CONDENSE <n>-path.
CONDENSE <n>-name.
CONDENSE <n>-type.
CONDENSE <n>-value.
<n>-index = lv_index.
<n>-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.

View File

@ -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

View File

@ -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(

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.