mirror of
https://github.com/abapGit/abapGit.git
synced 2025-04-30 20:03:20 +08:00
ajson, Automatic Update (#4961)
This commit is contained in:
parent
117aa2b474
commit
7e55a358cf
|
@ -133,14 +133,30 @@ CLASS lcl_json_parser DEFINITION FINAL.
|
|||
RAISING
|
||||
zcx_abapgit_ajson_error cx_sxml_error.
|
||||
|
||||
METHODS _get_location
|
||||
IMPORTING
|
||||
iv_json TYPE string
|
||||
iv_offset TYPE i
|
||||
RETURNING
|
||||
VALUE(rv_location) TYPE string.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
CLASS lcl_json_parser IMPLEMENTATION.
|
||||
|
||||
METHOD parse.
|
||||
DATA lx_sxml_parse TYPE REF TO cx_sxml_parse_error.
|
||||
DATA lx_sxml TYPE REF TO cx_sxml_error.
|
||||
DATA lv_location TYPE string.
|
||||
TRY.
|
||||
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 ).
|
||||
zcx_abapgit_ajson_error=>raise(
|
||||
iv_msg = |Json parsing error (SXML): { lx_sxml_parse->get_text( ) }|
|
||||
iv_location = lv_location ).
|
||||
CATCH cx_sxml_error INTO lx_sxml.
|
||||
zcx_abapgit_ajson_error=>raise(
|
||||
iv_msg = |Json parsing error (SXML): { lx_sxml->get_text( ) }|
|
||||
|
@ -148,6 +164,43 @@ CLASS lcl_json_parser IMPLEMENTATION.
|
|||
ENDTRY.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD _get_location.
|
||||
|
||||
DATA lv_json TYPE string.
|
||||
DATA lv_offset TYPE i.
|
||||
DATA lt_text TYPE TABLE OF string.
|
||||
DATA lv_text TYPE string.
|
||||
DATA lv_line TYPE i.
|
||||
DATA lv_pos TYPE i.
|
||||
|
||||
lv_offset = iv_offset.
|
||||
IF lv_offset < 0.
|
||||
lv_offset = 0.
|
||||
ENDIF.
|
||||
IF lv_offset > strlen( iv_json ).
|
||||
lv_offset = strlen( iv_json ).
|
||||
ENDIF.
|
||||
|
||||
lv_json = iv_json(lv_offset).
|
||||
|
||||
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf
|
||||
IN lv_json WITH cl_abap_char_utilities=>newline.
|
||||
|
||||
SPLIT lv_json AT cl_abap_char_utilities=>newline INTO TABLE lt_text.
|
||||
|
||||
lv_line = lines( lt_text ).
|
||||
IF lv_line = 0.
|
||||
lv_line = 1.
|
||||
lv_pos = 1.
|
||||
ELSE.
|
||||
READ TABLE lt_text INDEX lv_line INTO lv_text.
|
||||
lv_pos = strlen( lv_text ) + 1.
|
||||
ENDIF.
|
||||
|
||||
rv_location = |Line { lv_line }, Offset { lv_pos }|.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD _parse.
|
||||
|
||||
DATA lo_reader TYPE REF TO if_sxml_reader.
|
||||
|
|
|
@ -147,7 +147,22 @@ CLASS ltcl_parser_test IMPLEMENTATION.
|
|||
exp = '*parsing error*' ).
|
||||
cl_abap_unit_assert=>assert_char_cp(
|
||||
act = lx_err->location
|
||||
exp = '@PARSER' ).
|
||||
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
|
||||
&& '}' ).
|
||||
cl_abap_unit_assert=>fail( 'Parsing of invalid JSON must fail (spec)' ).
|
||||
CATCH zcx_abapgit_ajson_error INTO lx_err.
|
||||
cl_abap_unit_assert=>assert_char_cp(
|
||||
act = lx_err->get_text( )
|
||||
exp = '*parsing error*' ).
|
||||
cl_abap_unit_assert=>assert_char_cp(
|
||||
act = lx_err->location
|
||||
exp = 'Line 3, Offset 8' ).
|
||||
ENDTRY.
|
||||
|
||||
ENDMETHOD.
|
||||
|
@ -2912,7 +2927,7 @@ CLASS ltcl_abap_to_json DEFINITION
|
|||
a TYPE string,
|
||||
b TYPE i,
|
||||
c TYPE abap_bool,
|
||||
d TYPE xfeld,
|
||||
d TYPE xsdboolean,
|
||||
END OF ty_struc,
|
||||
tt_struc TYPE STANDARD TABLE OF ty_struc WITH DEFAULT KEY,
|
||||
BEGIN OF ty_struc_complex.
|
||||
|
@ -2929,7 +2944,7 @@ CLASS ltcl_abap_to_json DEFINITION
|
|||
METHODS set_value_string FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_value_true FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_value_false FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_value_xfeld FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_value_xsdboolean FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_null FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_obj FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
METHODS set_array FOR TESTING RAISING zcx_abapgit_ajson_error.
|
||||
|
@ -3032,18 +3047,17 @@ CLASS ltcl_abap_to_json IMPLEMENTATION.
|
|||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD set_value_xfeld.
|
||||
METHOD set_value_xsdboolean.
|
||||
|
||||
DATA lo_nodes_exp TYPE REF TO lcl_nodes_helper.
|
||||
DATA lt_nodes TYPE zif_abapgit_ajson=>ty_nodes_tt.
|
||||
|
||||
" xfeld
|
||||
DATA lv_xfeld TYPE xfeld.
|
||||
DATA lv_xsdboolean TYPE xsdboolean.
|
||||
CREATE OBJECT lo_nodes_exp.
|
||||
lo_nodes_exp->add( ' | |bool |true ||' ).
|
||||
|
||||
lv_xfeld = 'X'.
|
||||
lt_nodes = lcl_abap_to_json=>convert( iv_data = lv_xfeld ).
|
||||
lv_xsdboolean = 'X'.
|
||||
lt_nodes = lcl_abap_to_json=>convert( iv_data = lv_xsdboolean ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lt_nodes
|
||||
|
|
|
@ -174,7 +174,7 @@
|
|||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_integrated", "method": "array_simple", "note": "Index not found in table @/10"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_integrated", "method": "item_order_integrated"},
|
||||
|
||||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_abap_to_json", "method": "set_value_xfeld", "note": "https://github.com/sbcgua/ajson/issues/75"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_abap_to_json", "method": "set_value_xsdboolean", "note": "https://github.com/sbcgua/ajson/issues/75"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_abap_to_json", "method": "set_obj", "note": "https://github.com/sbcgua/ajson/issues/75"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_abap_to_json", "method": "set_array", "note": "https://github.com/sbcgua/ajson/issues/75"},
|
||||
{"object": "ZCL_ABAPGIT_AJSON", "class": "ltcl_abap_to_json", "method": "set_complex_obj", "note": "https://github.com/sbcgua/ajson/issues/75"},
|
||||
|
|
Loading…
Reference in New Issue
Block a user