All files / src/objects/aff zcl_abapgit_json_path.clas.abap

96.15% Statements 50/52
0% Branches 0/1
100% Functions 0/0
96.15% Lines 50/52

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 531x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_json_path DEFINITION PUBLIC CREATE PUBLIC.
  PUBLIC SECTION.
    METHODS: serialize
      IMPORTING iv_json          TYPE string
      RETURNING VALUE(rt_result) TYPE string_table
      RAISING   zcx_abapgit_exception.
    METHODS: deserialize
      IMPORTING it_json_path     TYPE string_table
      RETURNING VALUE(rv_result) TYPE string
      RAISING   zcx_abapgit_exception.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.
 
 
 
CLASS zcl_abapgit_json_path IMPLEMENTATION.
 
 
  METHOD deserialize.
 
    rv_result = lcl_json_path=>deserialize( it_json_path ).
 
  ENDMETHOD.
 
 
  METHOD serialize.
    DATA: lo_json_path    TYPE REF TO lcl_json_path,
          lv_json_xstring TYPE xstring,
          lt_root_path    TYPE string_table,
          lo_reader       TYPE REF TO if_sxml_reader,
          lx_parse_error  TYPE REF TO cx_sxml_parse_error.
 
    lv_json_xstring = zcl_abapgit_convert=>string_to_xstring_utf8( iv_json ).
    lo_reader = cl_sxml_string_reader=>create( input = lv_json_xstring ).
 
    TRY.
        IF lo_reader->read_next_node( ) IS INITIAL.
          RETURN.
        ENDIF.
      CATCH cx_sxml_parse_error INTO lx_parse_error.
        zcx_abapgit_exception=>raise_with_text( lx_parse_error ).
    ENDTRY.
 
    APPEND `$` TO lt_root_path.
 
    CREATE OBJECT lo_json_path.
    lo_json_path->serialize_rec( EXPORTING io_reader     = lo_reader
                                           it_path       = lt_root_path
                                 CHANGING  ct_json_paths = rt_result ).
  ENDMETHOD.
ENDCLASS.