diff --git a/changelog.txt b/changelog.txt index 2e8a8ed..d6dcf0c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -11,6 +11,7 @@ Legend v1.1.11, 2024-?? ------------------ * Fix touch_array with keep order (#178, @mbtools) +* Fix conversion of string to packed #179 v1.1.10, 2024-02-04 ------------------ diff --git a/src/core/zcl_ajson.clas.locals_imp.abap b/src/core/zcl_ajson.clas.locals_imp.abap index c42e7f2..f6b6087 100644 --- a/src/core/zcl_ajson.clas.locals_imp.abap +++ b/src/core/zcl_ajson.clas.locals_imp.abap @@ -983,12 +983,19 @@ class lcl_json_to_abap implementation. when zif_ajson_types=>node_type-string. " TODO: check type ? - if is_node_type-type_kind = lif_kind=>date and is_node-value is not initial. - = to_date( is_node-value ). - elseif is_node_type-type_kind = lif_kind=>time and is_node-value is not initial. - = to_time( is_node-value ). - elseif is_node_type-type_kind = lif_kind=>packed and is_node-value is not initial. - = to_timestamp( is_node-value ). + if is_node-value is not initial. + if is_node_type-type_kind = lif_kind=>date. + = to_date( is_node-value ). + elseif is_node_type-type_kind = lif_kind=>time. + = to_time( is_node-value ). + elseif is_node_type-dd->absolute_name = '\TYPE=TIMESTAMP' + or is_node_type-dd->absolute_name = '\TYPE=TIMESTAMPL'. + = to_timestamp( is_node-value ). + elseif is_node_type-type_kind = lif_kind=>packed. " Number as a string, but not a timestamp + = is_node-value. + else. + = is_node-value. + endif. else. = is_node-value. endif. diff --git a/src/core/zcl_ajson.clas.testclasses.abap b/src/core/zcl_ajson.clas.testclasses.abap index 4a66ba7..e5a1660 100644 --- a/src/core/zcl_ajson.clas.testclasses.abap +++ b/src/core/zcl_ajson.clas.testclasses.abap @@ -1407,6 +1407,7 @@ class ltcl_json_to_abap definition timestamp1 type timestamp, timestamp2 type timestamp, timestamp3 type timestamp, + timestamp4 type timestampl, end of ty_complex. methods to_abap_struc @@ -1460,6 +1461,9 @@ class ltcl_json_to_abap definition methods to_abap_time for testing raising cx_static_check. + methods to_abap_str_to_packed + for testing + raising cx_static_check. endclass. class zcl_ajson definition local friends ltcl_json_to_abap. @@ -1489,6 +1493,7 @@ class ltcl_json_to_abap implementation. lo_nodes->add( '/ |timestamp1 |str |2020-07-28T00:00:00 | ' ). lo_nodes->add( '/ |timestamp2 |str |2020-07-28T00:00:00Z | ' ). lo_nodes->add( '/ |timestamp3 |str |2020-07-28T01:00:00+01:00 | ' ). + lo_nodes->add( '/ |timestamp4 |str |2020-07-28T01:00:00+01:00 | ' ). create object lo_cut. lo_cut->to_abap( @@ -1507,6 +1512,7 @@ class ltcl_json_to_abap implementation. ls_exp-timestamp1 = lv_exp_timestamp. ls_exp-timestamp2 = lv_exp_timestamp. ls_exp-timestamp3 = lv_exp_timestamp. + ls_exp-timestamp4 = lv_exp_timestamp. cl_abap_unit_assert=>assert_equals( act = ls_mock @@ -1574,6 +1580,28 @@ class ltcl_json_to_abap implementation. endmethod. + method to_abap_str_to_packed. + + data lo_cut type ref to lcl_json_to_abap. + data lv_act type p length 10 decimals 3. + data lo_nodes type ref to lcl_nodes_helper. + + create object lo_nodes. + lo_nodes->add( ' | |str |1.3333 | ' ). + + create object lo_cut. + lo_cut->to_abap( + exporting + it_nodes = lo_nodes->sorted( ) + changing + c_container = lv_act ). + + cl_abap_unit_assert=>assert_equals( + act = lv_act + exp = '1.333' ). + + endmethod. + method to_abap_value. data lo_cut type ref to lcl_json_to_abap.