ajson, Automatic Update (#6245)

This commit is contained in:
github-actions[bot] 2023-05-01 12:27:55 +02:00 committed by GitHub
parent feb6adf0a1
commit c5a3b75c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 1 deletions

View File

@ -45,6 +45,7 @@ CLASS zcl_abapgit_ajson DEFINITION
mt_json_tree FOR zif_abapgit_ajson~mt_json_tree,
keep_item_order FOR zif_abapgit_ajson~keep_item_order,
format_datetime FOR zif_abapgit_ajson~format_datetime,
to_abap_corresponding_only FOR zif_abapgit_ajson~to_abap_corresponding_only,
freeze FOR zif_abapgit_ajson~freeze.
CLASS-METHODS parse
@ -62,6 +63,7 @@ CLASS zcl_abapgit_ajson DEFINITION
!ii_custom_mapping TYPE REF TO zif_abapgit_ajson_mapping OPTIONAL
iv_keep_item_order TYPE abap_bool DEFAULT abap_false
iv_format_datetime TYPE abap_bool DEFAULT abap_true
iv_to_abap_corresponding_only TYPE abap_bool DEFAULT abap_false
RETURNING
VALUE(ro_instance) TYPE REF TO zcl_abapgit_ajson.
@ -79,11 +81,13 @@ CLASS zcl_abapgit_ajson DEFINITION
METHODS constructor
IMPORTING
iv_keep_item_order TYPE abap_bool DEFAULT abap_false
iv_format_datetime TYPE abap_bool DEFAULT abap_true.
iv_format_datetime TYPE abap_bool DEFAULT abap_true
iv_to_abap_corresponding_only TYPE abap_bool DEFAULT abap_false.
CLASS-METHODS new
IMPORTING
iv_keep_item_order TYPE abap_bool DEFAULT abap_false
iv_format_datetime TYPE abap_bool DEFAULT abap_true
iv_to_abap_corresponding_only TYPE abap_bool DEFAULT abap_false
RETURNING
VALUE(ro_instance) TYPE REF TO zcl_abapgit_ajson.
@ -127,6 +131,7 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION.
METHOD constructor.
ms_opts-keep_item_order = iv_keep_item_order.
ms_opts-to_abap_corresponding_only = iv_to_abap_corresponding_only.
format_datetime( iv_format_datetime ).
ENDMETHOD.
@ -134,6 +139,7 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION.
METHOD create_empty.
CREATE OBJECT ro_instance
EXPORTING
iv_to_abap_corresponding_only = iv_to_abap_corresponding_only
iv_format_datetime = iv_format_datetime
iv_keep_item_order = iv_keep_item_order.
ro_instance->mi_custom_mapping = ii_custom_mapping.
@ -150,6 +156,7 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION.
CREATE OBJECT ro_instance
EXPORTING
iv_to_abap_corresponding_only = ii_source_json->opts( )-to_abap_corresponding_only
iv_format_datetime = ii_source_json->opts( )-format_datetime
iv_keep_item_order = ii_source_json->opts( )-keep_item_order.
@ -228,6 +235,7 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION.
METHOD new.
CREATE OBJECT ro_instance
EXPORTING
iv_to_abap_corresponding_only = iv_to_abap_corresponding_only
iv_format_datetime = iv_format_datetime
iv_keep_item_order = iv_keep_item_order.
ENDMETHOD.
@ -927,6 +935,7 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION.
CLEAR ev_container.
CREATE OBJECT lo_to_abap
EXPORTING
iv_corresponding = boolc( iv_corresponding = abap_true OR ms_opts-to_abap_corresponding_only = abap_true )
ii_custom_mapping = mi_custom_mapping.
lo_to_abap->to_abap(
@ -936,4 +945,10 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION.
c_container = ev_container ).
ENDMETHOD.
METHOD zif_abapgit_ajson~to_abap_corresponding_only.
ms_opts-to_abap_corresponding_only = iv_enable.
ri_json = me.
ENDMETHOD.
ENDCLASS.

View File

@ -1391,9 +1391,17 @@ CLASS ltcl_json_to_abap DEFINITION
METHODS to_abap_corresponding_negative
FOR TESTING
RAISING zcx_abapgit_ajson_error.
METHODS to_abap_corresponding_public
FOR TESTING
RAISING zcx_abapgit_ajson_error.
METHODS to_abap_corresponding_pub_neg
FOR TESTING
RAISING zcx_abapgit_ajson_error.
ENDCLASS.
CLASS zcl_abapgit_ajson DEFINITION LOCAL FRIENDS ltcl_json_to_abap.
CLASS ltcl_json_to_abap IMPLEMENTATION.
METHOD to_abap_struc.
@ -1983,6 +1991,74 @@ CLASS ltcl_json_to_abap IMPLEMENTATION.
ENDMETHOD.
METHOD to_abap_corresponding_public.
DATA lo_cut TYPE REF TO zcl_abapgit_ajson.
DATA ls_act TYPE ty_struc.
DATA ls_exp TYPE ty_struc.
DATA li_json TYPE REF TO zif_abapgit_ajson.
DATA lo_nodes TYPE REF TO lcl_nodes_helper.
CREATE OBJECT lo_nodes.
lo_nodes->add( ' | |object | | ' ).
lo_nodes->add( '/ |a |str |test | ' ).
lo_nodes->add( '/ |c |num |24022022 | ' ).
ls_exp-a = 'test'.
CREATE OBJECT lo_cut.
lo_cut->mt_json_tree = lo_nodes->mt_nodes.
lo_cut->to_abap(
EXPORTING
iv_corresponding = abap_true
IMPORTING
ev_container = ls_act ).
cl_abap_unit_assert=>assert_equals(
act = ls_act
exp = ls_exp ).
CLEAR ls_act.
li_json = lo_cut->to_abap_corresponding_only( ).
li_json->to_abap( IMPORTING ev_container = ls_act ).
cl_abap_unit_assert=>assert_equals(
act = ls_act
exp = ls_exp ).
ENDMETHOD.
METHOD to_abap_corresponding_pub_neg.
DATA lo_cut TYPE REF TO zcl_abapgit_ajson.
DATA ls_act TYPE ty_struc.
DATA ls_exp TYPE ty_struc.
DATA lo_nodes TYPE REF TO lcl_nodes_helper.
DATA lx TYPE REF TO zcx_abapgit_ajson_error.
CREATE OBJECT lo_nodes.
lo_nodes->add( ' | |object | | ' ).
lo_nodes->add( '/ |a |str |test | ' ).
lo_nodes->add( '/ |c |num |24022022 | ' ).
ls_exp-a = 'test'.
CREATE OBJECT lo_cut.
lo_cut->mt_json_tree = lo_nodes->mt_nodes.
TRY.
lo_cut->to_abap( IMPORTING ev_container = ls_act ).
cl_abap_unit_assert=>fail( ).
CATCH zcx_abapgit_ajson_error INTO lx.
cl_abap_unit_assert=>assert_equals(
act = lx->message
exp = 'Path not found' ).
ENDTRY.
ENDMETHOD.
ENDCLASS.
**********************************************************************

View File

@ -10,6 +10,7 @@ INTERFACE zif_abapgit_ajson
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
@ -49,6 +50,11 @@ INTERFACE zif_abapgit_ajson
iv_use_iso TYPE abap_bool DEFAULT abap_true
RETURNING
VALUE(ri_json) TYPE REF TO zif_abapgit_ajson.
METHODS to_abap_corresponding_only
IMPORTING
iv_enable TYPE abap_bool DEFAULT abap_true
RETURNING
VALUE(ri_json) TYPE REF TO zif_abapgit_ajson.
METHODS opts
RETURNING
VALUE(rs_opts) TYPE ty_opts.
@ -126,6 +132,8 @@ INTERFACE zif_abapgit_ajson
VALUE(ri_json) TYPE REF TO zif_abapgit_ajson.
METHODS to_abap
IMPORTING
iv_corresponding TYPE abap_bool DEFAULT abap_false
EXPORTING
ev_container TYPE any
RAISING