mirror of
https://github.com/abapGit/abapGit.git
synced 2025-04-30 20:03:20 +08:00
ajson, Automatic Update (#5584)
This commit is contained in:
parent
2ffdab2526
commit
0e5e3b0cf5
10
package.json
10
package.json
|
@ -25,12 +25,12 @@
|
|||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@abaplint/cli": "^2.90.0",
|
||||
"@abaplint/runtime": "^2.0.22",
|
||||
"@abaplint/transpiler-cli": "^2.0.22",
|
||||
"@abaplint/cli": "^2.90.6",
|
||||
"@abaplint/runtime": "^2.0.26",
|
||||
"@abaplint/transpiler-cli": "^2.0.26",
|
||||
"@abaplint/database-sqlite": "^2.0.11",
|
||||
"abapmerge": "^0.14.3",
|
||||
"c8": "^7.11.2",
|
||||
"eslint": "^8.14.0"
|
||||
"c8": "^7.11.3",
|
||||
"eslint": "^8.16.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,8 @@ CLASS zcl_abapgit_ajson DEFINITION
|
|||
RAISING
|
||||
zcx_abapgit_ajson_error .
|
||||
|
||||
METHODS constructor.
|
||||
|
||||
PROTECTED SECTION.
|
||||
|
||||
PRIVATE SECTION.
|
||||
|
@ -103,6 +105,11 @@ ENDCLASS.
|
|||
CLASS zcl_abapgit_ajson IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD constructor.
|
||||
format_datetime( abap_true ).
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD create_empty.
|
||||
CREATE OBJECT ro_instance.
|
||||
ro_instance->mi_custom_mapping = ii_custom_mapping.
|
||||
|
@ -332,8 +339,9 @@ CLASS zcl_abapgit_ajson IMPLEMENTATION.
|
|||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD zif_abapgit_ajson~format_datetime.
|
||||
mv_format_datetime = abap_true.
|
||||
mv_format_datetime = iv_use_iso.
|
||||
ri_json = me.
|
||||
ENDMETHOD.
|
||||
|
||||
|
|
|
@ -1063,7 +1063,7 @@ CLASS lcl_abap_to_json DEFINITION FINAL.
|
|||
|
||||
METHODS convert_ajson
|
||||
IMPORTING
|
||||
io_json TYPE REF TO zcl_abapgit_ajson
|
||||
io_json TYPE REF TO zif_abapgit_ajson
|
||||
is_prefix TYPE zif_abapgit_ajson=>ty_path_name
|
||||
iv_index TYPE i DEFAULT 0
|
||||
CHANGING
|
||||
|
@ -1206,7 +1206,9 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
|
|||
|
||||
WHEN OTHERS.
|
||||
|
||||
IF io_type->type_kind = cl_abap_typedescr=>typekind_dref.
|
||||
IF io_type->type_kind = cl_abap_typedescr=>typekind_dref OR iv_data IS INITIAL.
|
||||
" Convert data references and initial references to other types (like ref to class or interface)
|
||||
" Initial references will result in "null"
|
||||
convert_ref(
|
||||
EXPORTING
|
||||
iv_data = iv_data
|
||||
|
@ -1439,7 +1441,7 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
|
|||
" and rtti seems to cache type descriptions really well (https://github.com/sbcgua/benchmarks.git)
|
||||
" the structures will be repeated in real life
|
||||
|
||||
ls_next_prefix-path = is_prefix-path && ls_root-name && '/'.
|
||||
ls_next_prefix-path = is_prefix-path && <root>-name && '/'.
|
||||
|
||||
LOOP AT lt_comps ASSIGNING <c>.
|
||||
|
||||
|
@ -1517,7 +1519,7 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
|
|||
lo_table ?= io_type.
|
||||
lo_ltype = lo_table->get_table_line_type( ).
|
||||
|
||||
ls_next_prefix-path = is_prefix-path && is_prefix-name && '/'.
|
||||
ls_next_prefix-path = is_prefix-path && <root>-name && '/'.
|
||||
ASSIGN iv_data TO <tab>.
|
||||
|
||||
lv_tabix = 1.
|
||||
|
|
|
@ -1864,6 +1864,7 @@ CLASS ltcl_writer_test DEFINITION FINAL
|
|||
METHODS set_obj_w_date_time FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_tab FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_tab_hashed FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_tab_nested_struct FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS prove_path_exists FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS delete_subtree FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS delete FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
|
@ -2155,11 +2156,11 @@ CLASS ltcl_writer_test IMPLEMENTATION.
|
|||
|
||||
" Prepare source
|
||||
CREATE OBJECT lo_nodes.
|
||||
lo_nodes->add( ' | |object | ||1' ).
|
||||
lo_nodes->add( '/ |x |object | ||3' ).
|
||||
lo_nodes->add( '/x/ |b |str |abc ||0' ).
|
||||
lo_nodes->add( '/x/ |c |num |10 ||0' ).
|
||||
lo_nodes->add( '/x/ |d |str |20220401 ||0' ).
|
||||
lo_nodes->add( ' | |object | ||1' ).
|
||||
lo_nodes->add( '/ |x |object | ||3' ).
|
||||
lo_nodes->add( '/x/ |b |str |abc ||0' ).
|
||||
lo_nodes->add( '/x/ |c |num |10 ||0' ).
|
||||
lo_nodes->add( '/x/ |d |str |2022-04-01 ||0' ).
|
||||
|
||||
li_writer->set(
|
||||
iv_path = '/x'
|
||||
|
@ -2266,6 +2267,56 @@ CLASS ltcl_writer_test IMPLEMENTATION.
|
|||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD set_tab_nested_struct.
|
||||
|
||||
TYPES:
|
||||
BEGIN OF ty_include,
|
||||
str TYPE string,
|
||||
int TYPE i,
|
||||
END OF ty_include,
|
||||
BEGIN OF ty_struct.
|
||||
INCLUDE TYPE ty_include.
|
||||
TYPES: dat TYPE xstring,
|
||||
END OF ty_struct,
|
||||
ty_tab TYPE STANDARD TABLE OF ty_struct WITH DEFAULT KEY.
|
||||
|
||||
DATA lo_nodes TYPE REF TO lcl_nodes_helper.
|
||||
DATA li_cut TYPE REF TO zif_abapgit_ajson.
|
||||
DATA ls_tab TYPE ty_struct.
|
||||
DATA lt_tab TYPE ty_tab.
|
||||
|
||||
li_cut = zcl_abapgit_ajson=>create_empty( ).
|
||||
|
||||
ls_tab-str = 'hello'.
|
||||
ls_tab-int = 123.
|
||||
ls_tab-dat = '4041'.
|
||||
INSERT ls_tab INTO TABLE lt_tab.
|
||||
ls_tab-str = 'world'.
|
||||
ls_tab-int = 456.
|
||||
ls_tab-dat = '6061'.
|
||||
INSERT ls_tab INTO TABLE lt_tab.
|
||||
|
||||
" prepare source
|
||||
CREATE OBJECT lo_nodes.
|
||||
lo_nodes->add( ' | |array | |0|2' ).
|
||||
lo_nodes->add( '/ |1 |object | |1|3' ).
|
||||
lo_nodes->add( '/ |2 |object | |2|3' ).
|
||||
lo_nodes->add( '/1/ |dat |str |4041 |0|0' ).
|
||||
lo_nodes->add( '/1/ |int |num |123 |0|0' ).
|
||||
lo_nodes->add( '/1/ |str |str |hello|0|0' ).
|
||||
lo_nodes->add( '/2/ |dat |str |6061 |0|0' ).
|
||||
lo_nodes->add( '/2/ |int |num |456 |0|0' ).
|
||||
lo_nodes->add( '/2/ |str |str |world|0|0' ).
|
||||
|
||||
li_cut->set(
|
||||
iv_path = '/'
|
||||
iv_val = lt_tab ).
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = li_cut->mt_json_tree
|
||||
exp = lo_nodes->sorted( ) ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD arrays.
|
||||
|
||||
DATA lo_cut TYPE REF TO zcl_abapgit_ajson.
|
||||
|
@ -2883,6 +2934,7 @@ CLASS ltcl_integrated DEFINITION
|
|||
METHODS stringify FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS item_order_integrated FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS chaining FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS push_json FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
|
@ -2999,6 +3051,7 @@ CLASS ltcl_integrated IMPLEMENTATION.
|
|||
DATA li_writer TYPE REF TO zif_abapgit_ajson.
|
||||
DATA lv_exp TYPE string.
|
||||
DATA: BEGIN OF ls_dummy, x TYPE i, END OF ls_dummy.
|
||||
DATA: BEGIN OF ls_data, str TYPE string, cls TYPE REF TO zcl_abapgit_ajson, END OF ls_data.
|
||||
|
||||
ls_dummy-x = 1.
|
||||
lo_cut = zcl_abapgit_ajson=>create_empty( ).
|
||||
|
@ -3066,6 +3119,19 @@ CLASS ltcl_integrated IMPLEMENTATION.
|
|||
act = lo_cut->stringify( iv_indent = 2 )
|
||||
exp = lv_exp ).
|
||||
|
||||
" structure with initial ref to class
|
||||
ls_data-str = 'test'.
|
||||
|
||||
li_writer = lo_cut.
|
||||
li_writer->set(
|
||||
iv_path = '/'
|
||||
iv_val = ls_data ).
|
||||
|
||||
lv_exp = '{"cls":null,"str":"test"}'.
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lo_cut->stringify( )
|
||||
exp = lv_exp ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD item_order_integrated.
|
||||
|
@ -3138,6 +3204,42 @@ CLASS ltcl_integrated IMPLEMENTATION.
|
|||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD push_json.
|
||||
|
||||
DATA li_cut TYPE REF TO zif_abapgit_ajson.
|
||||
DATA li_sub TYPE REF TO zif_abapgit_ajson.
|
||||
DATA lv_act TYPE string.
|
||||
DATA lv_exp TYPE string.
|
||||
|
||||
li_cut = zcl_abapgit_ajson=>create_empty( ).
|
||||
li_sub = zcl_abapgit_ajson=>create_empty( )->set(
|
||||
iv_path = 'a'
|
||||
iv_val = '1' ).
|
||||
|
||||
li_cut->touch_array( '/list' ).
|
||||
li_cut->push(
|
||||
iv_path = '/list'
|
||||
iv_val = 'hello' ).
|
||||
li_cut->push(
|
||||
iv_path = '/list'
|
||||
iv_val = zcl_abapgit_ajson=>create_empty( )->set(
|
||||
iv_path = 'a'
|
||||
iv_val = '1' ) ).
|
||||
li_cut->push(
|
||||
iv_path = '/list'
|
||||
iv_val = zcl_abapgit_ajson=>create_empty( )->set(
|
||||
iv_path = '/'
|
||||
iv_val = 'world' ) ).
|
||||
|
||||
lv_act = li_cut->stringify( ).
|
||||
lv_exp = '{"list":["hello",{"a":"1"},"world"]}'.
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lv_act
|
||||
exp = lv_exp ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
**********************************************************************
|
||||
|
|
|
@ -7,6 +7,7 @@ CLASS ltcl_camel_case DEFINITION FINAL FOR TESTING
|
|||
to_abap FOR TESTING RAISING zcx_abapgit_ajson_error,
|
||||
to_json FOR TESTING RAISING zcx_abapgit_ajson_error,
|
||||
to_json_nested_struc FOR TESTING RAISING zcx_abapgit_ajson_error,
|
||||
to_json_nested_table FOR TESTING RAISING zcx_abapgit_ajson_error,
|
||||
to_json_first_lower FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
|
||||
ENDCLASS.
|
||||
|
@ -95,6 +96,38 @@ CLASS ltcl_camel_case IMPLEMENTATION.
|
|||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD to_json_nested_table.
|
||||
|
||||
DATA:
|
||||
lo_ajson TYPE REF TO zcl_abapgit_ajson,
|
||||
li_mapping TYPE REF TO zif_abapgit_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 = zcl_abapgit_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.
|
||||
|
||||
lo_ajson = zcl_abapgit_ajson=>create_empty( ii_custom_mapping = li_mapping ).
|
||||
|
||||
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.
|
||||
|
||||
|
||||
METHOD to_json_first_lower.
|
||||
|
||||
DATA:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
INTERFACE zif_abapgit_ajson
|
||||
PUBLIC.
|
||||
|
||||
CONSTANTS version TYPE string VALUE 'v1.1.3'. "#EC NOTEXT
|
||||
CONSTANTS version TYPE string VALUE 'v1.1.4'. "#EC NOTEXT
|
||||
CONSTANTS origin TYPE string VALUE 'https://github.com/sbcgua/ajson'. "#EC NOTEXT
|
||||
CONSTANTS license TYPE string VALUE 'MIT'. "#EC NOTEXT
|
||||
|
||||
|
@ -49,6 +49,8 @@ INTERFACE zif_abapgit_ajson
|
|||
RETURNING
|
||||
VALUE(ri_json) TYPE REF TO zif_abapgit_ajson.
|
||||
METHODS format_datetime
|
||||
IMPORTING
|
||||
iv_use_iso TYPE abap_bool DEFAULT abap_true
|
||||
RETURNING
|
||||
VALUE(ri_json) TYPE REF TO zif_abapgit_ajson.
|
||||
|
||||
|
|
|
@ -169,11 +169,14 @@
|
|||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_abap_to_json", "method": "set_array"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_abap_to_json", "method": "set_complex_obj"},
|
||||
|
||||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_writer_test", "method": "set_tab_nested_struct"},
|
||||
|
||||
{"object": "ZCL_ABAPGIT_UI_INJECTOR", "class": "ltcl_no_dependency_injection", "method": "no_injection", "note": "RTTI? class absolute_name"},
|
||||
{"object": "ZCL_ABAPGIT_UI_INJECTOR", "class": "ltcl_simple_dependency_inject", "method": "simple_injection", "note": "RTTI?"},
|
||||
|
||||
{"object": "ZCL_ABAPGIT_AJSON_MAPPING", "class": "ltcl_camel_case", "method": "to_abap", "note": "secondary key fields? READ WITH KEY, Path not found @/FieldData"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON_MAPPING", "class": "ltcl_camel_case", "method": "to_json"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON_MAPPING", "class": "ltcl_camel_case", "method": "to_json_nested_table"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON_MAPPING", "class": "ltcl_camel_case", "method": "to_json_first_lower"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON_MAPPING", "class": "ltcl_camel_case", "method": "to_json_nested_struc"},
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user