Skip to content

Instantly share code, notes, and snippets.

@larshp
Created September 6, 2021 13:22
Show Gist options
  • Save larshp/8dfb3904a1d1d6d741662e741bd0c87e to your computer and use it in GitHub Desktop.
Save larshp/8dfb3904a1d1d6d741662e741bd0c87e to your computer and use it in GitHub Desktop.
REPORT zfoobar5.
CLASS lcl_mapping DEFINITION.
PUBLIC SECTION.
INTERFACES zif_abapgit_ajson_mapping.
ENDCLASS.
CLASS lcl_mapping IMPLEMENTATION.
METHOD zif_abapgit_ajson_mapping~to_abap.
ENDMETHOD.
METHOD zif_abapgit_ajson_mapping~to_json.
TYPES ty_token TYPE c LENGTH 255.
DATA lt_tokens TYPE STANDARD TABLE OF ty_token.
FIELD-SYMBOLS <token> LIKE LINE OF lt_tokens.
rv_result = iv_name.
IF iv_path = '/' AND iv_name = 'schema'.
rv_result = '$schema'.
ELSE.
SPLIT rv_result AT `_` INTO TABLE lt_tokens.
LOOP AT lt_tokens ASSIGNING <token> FROM 2.
TRANSLATE <token>(1) TO UPPER CASE.
ENDLOOP.
CONCATENATE LINES OF lt_tokens INTO rv_result.
ENDIF.
ENDMETHOD.
ENDCLASS.
FORM run RAISING cx_static_check.
DATA intf TYPE zif_aff_intf_v1=>ty_main.
DATA li_ajson TYPE REF TO zif_abapgit_ajson.
intf-header-description = 'hello world'.
li_ajson = zcl_abapgit_ajson=>create_empty( ii_custom_mapping = NEW lcl_mapping( ) ).
li_ajson->keep_item_order( ).
li_ajson->set(
iv_path = '/'
iv_val = intf ).
DATA(json) = li_ajson->stringify( 2 ).
BREAK-POINT.
ENDFORM.
START-OF-SELECTION.
PERFORM run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment