mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 04:08:27 +08:00
ajson, Automatic Update (#5682)
This commit is contained in:
parent
97558e0b73
commit
b6de2d0dc8
|
@ -26,8 +26,8 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@abaplint/cli": "^2.91.8",
|
||||
"@abaplint/runtime": "^2.0.63",
|
||||
"@abaplint/transpiler-cli": "^2.0.63",
|
||||
"@abaplint/runtime": "^2.0.64",
|
||||
"@abaplint/transpiler-cli": "^2.0.64",
|
||||
"@abaplint/database-sqlite": "^2.0.58",
|
||||
"abapmerge": "^0.14.7",
|
||||
"c8": "^7.11.3",
|
||||
|
|
|
@ -1358,12 +1358,6 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
|
|||
ls_node-index = iv_index.
|
||||
ls_node-order = iv_item_order.
|
||||
|
||||
IF mi_custom_mapping IS BOUND.
|
||||
ls_node-name = mi_custom_mapping->to_json(
|
||||
iv_path = is_prefix-path
|
||||
iv_name = is_prefix-name ).
|
||||
ENDIF.
|
||||
|
||||
IF ls_node-name IS INITIAL.
|
||||
ls_node-name = is_prefix-name.
|
||||
ENDIF.
|
||||
|
@ -1453,6 +1447,7 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
|
|||
DATA lo_struc TYPE REF TO cl_abap_structdescr.
|
||||
DATA lt_comps TYPE cl_abap_structdescr=>component_table.
|
||||
DATA ls_next_prefix LIKE is_prefix.
|
||||
DATA lv_mapping_prefix_name LIKE is_prefix-name.
|
||||
DATA lv_item_order TYPE i.
|
||||
DATA ls_root LIKE LINE OF ct_nodes.
|
||||
|
||||
|
@ -1498,6 +1493,7 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
|
|||
ls_next_prefix-path = is_prefix-path && <root>-name && '/'.
|
||||
|
||||
LOOP AT lt_comps ASSIGNING <c>.
|
||||
CLEAR lv_mapping_prefix_name.
|
||||
|
||||
IF <c>-as_include = abap_true.
|
||||
|
||||
|
@ -1517,6 +1513,15 @@ CLASS lcl_abap_to_json IMPLEMENTATION.
|
|||
ASSIGN COMPONENT <c>-name OF STRUCTURE iv_data TO <val>.
|
||||
ASSERT sy-subrc = 0.
|
||||
|
||||
IF mi_custom_mapping IS BOUND AND <c>-type->kind = cl_abap_typedescr=>kind_elem.
|
||||
lv_mapping_prefix_name = mi_custom_mapping->to_json( iv_path = ls_next_prefix-path
|
||||
iv_name = ls_next_prefix-name ).
|
||||
ENDIF.
|
||||
|
||||
IF lv_mapping_prefix_name IS NOT INITIAL.
|
||||
ls_next_prefix-name = lv_mapping_prefix_name.
|
||||
ENDIF.
|
||||
|
||||
IF mv_keep_item_order = abap_true.
|
||||
lv_item_order = <root>-children.
|
||||
ENDIF.
|
||||
|
|
|
@ -4,6 +4,7 @@ CLASS ltcl_camel_case DEFINITION FINAL FOR TESTING
|
|||
|
||||
PRIVATE SECTION.
|
||||
METHODS:
|
||||
from_json_to_json FOR TESTING RAISING zcx_abapgit_ajson_error,
|
||||
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,
|
||||
|
@ -16,6 +17,26 @@ ENDCLASS.
|
|||
CLASS ltcl_camel_case IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD from_json_to_json.
|
||||
|
||||
DATA:
|
||||
lo_ajson TYPE REF TO zcl_abapgit_ajson.
|
||||
|
||||
lo_ajson =
|
||||
zcl_abapgit_ajson=>parse(
|
||||
iv_json = `{"fieldData":"field_value"}`
|
||||
ii_custom_mapping = zcl_abapgit_ajson_mapping=>create_camel_case( iv_first_json_upper = abap_false ) ).
|
||||
|
||||
lo_ajson->set_string( iv_path = `/fieldData`
|
||||
iv_val = 'E' ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lo_ajson->stringify( )
|
||||
exp = '{"fieldData":"E"}' ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD to_abap.
|
||||
|
||||
DATA:
|
||||
|
@ -164,8 +185,12 @@ CLASS ltcl_fields DEFINITION FINAL FOR TESTING
|
|||
|
||||
PRIVATE SECTION.
|
||||
METHODS:
|
||||
to_json_without_path FOR TESTING RAISING zcx_abapgit_ajson_error,
|
||||
to_json_with_path FOR TESTING RAISING zcx_abapgit_ajson_error,
|
||||
to_abap FOR TESTING RAISING zcx_abapgit_ajson_error,
|
||||
to_json FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
to_json IMPORTING iv_path TYPE string RETURNING VALUE(rv_result) TYPE string RAISING zcx_abapgit_ajson_error.
|
||||
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
@ -209,6 +234,24 @@ CLASS ltcl_fields IMPLEMENTATION.
|
|||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD to_json_without_path.
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = to_json( `/` )
|
||||
exp = '{"field":"value","json.field":"field_value"}' ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD to_json_with_path.
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = to_json( '/samplePath' )
|
||||
exp = '{"samplePath":{"field":"value","json.field":"field_value"}}' ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD to_json.
|
||||
|
||||
DATA:
|
||||
|
@ -234,12 +277,10 @@ CLASS ltcl_fields IMPLEMENTATION.
|
|||
|
||||
lo_ajson = zcl_abapgit_ajson=>create_empty( ii_custom_mapping = li_mapping ).
|
||||
|
||||
lo_ajson->set( iv_path = '/'
|
||||
lo_ajson->set( iv_path = iv_path
|
||||
iv_val = ls_result ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lo_ajson->stringify( )
|
||||
exp = '{"field":"value","json.field":"field_value"}' ).
|
||||
rv_result = lo_ajson->stringify( ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user