sbcgua / ajson

Yet another json parser serializer for ABAP
MIT License
50 stars 15 forks source link

Skip empty nodes at serialization #121

Open jrodriguez-rc opened 2 years ago

jrodriguez-rc commented 2 years ago

This new option will skip all the nodes that have no content:

sbcgua commented 2 years ago

Do you mean without filter ? https://github.com/sbcgua/ajson#predefined-filters

Also:

mbtools commented 4 months ago

I would go with the most famous isEmpty implementation: https://github.com/lodash/lodash/blob/main/src/isEmpty.ts

It's working differently now:

https://github.com/sbcgua/ajson/blob/2504b311e7e4695f1aea94f11c3cc883c4df8391/src/libs/zcl_ajson_filter_lib.clas.locals_imp.abap#L11-L18

I changed my custom empty filter to the following which also removes null and initial numbers (zero).

    rv_keep = boolc(
      ( iv_visit = zif_ajson_filter=>visit_type-value AND
        ( is_node-type = zif_ajson_types=>node_type-string AND is_node-value IS NOT INITIAL OR
          is_node-type = zif_ajson_types=>node_type-boolean OR
          is_node-type = zif_ajson_types=>node_type-number AND is_node-value <> 0 ) ) OR
      ( iv_visit <> zif_ajson_filter=>visit_type-value AND is_node-children > 0 ) ).