Item filter
sbcgua opened this issue · 10 comments
Follows #71 (comment) @larshp
perhaps something like adding this method to the custom mapping interface
methods to_json_skip_value importing io_type type ref to cl_abap_typedescr is_node type ty_node, returning value(rv_skip) type abap_bool.if it returns rv_skip = abap_true, then skip the value, else as normal
- This seems to be not about skipping but about filtering, the implementation may decide to skip filled values too
- Thus it doesn't match mapper semantics, it is a separate
filter
interface - Also because of performance considerations. Mapper without filter will call extra method each time and vice versa
interface zif_ajson_filter " zif_ajson_node_filter ?
methods filter
importing
io_type type ref to cl_abap_typedescr
is_node type ty_node,
returning
value(rv_KEEP) type abap_bool.
true,
is_node
has value as a string, perhaps also pass a reference to the abap value?
NB, thoughts: typical usages to maybe implement within the package:
- filter all empty nodes
- filter out specific paths
- maybe, makes sense to coordinate with #63 (in the long run ...)
- maybe implement filter chains (multiple filters)
push( X )
push( Y )
push( Z )
where Y is filtered, should result in [X, null, Z]
, isn't it ?
- Really draft at this moment
- children count fails
- merging ajson has a potential misuse
- and value is not transferred to the filter (e.g. to hide whole structure or table)
- a lot of code duplication...
By the way do you need io_type in the filter ? I guess not if value itself is passed ? It is no very clear what to pass therein some cases (see lo_null_type)
io_type: perhaps the value
part of is_node
is enough, but I'd like to be able to do "if value is initial then skip field", the to be able to determine if the value is initial, it requires the type of the node? but again, perhaps the json type(part of is_node) is enough
OK, so it is kind of ready though needs more testing and unit testing ...
li_json_filtered = zcl_ajson=>create_from(
ii_source_json = li_json_source
ii_filter = zcl_ajson_filter_lib=>create_empty_filter( ) ).
also implemented "in the box" filtering by path and "and-filtering" to combine filters. See UTs of ZCL_AJSON_FILTER_LIB
- https://github.com/sbcgua/ajson/pull/76/files#diff-4eed2314d42108a56f62bcc604d05b97749a05068d82d3d63800495d84fd0a16
The interface zif_ajson_filter
allows creating custom filters. Note iv_visit
param - objects and arrays trigger filter 2 times - on open and on close. On open children = original value, on close children = filtered value (so after filtering child nodes). Array indexes are re-numbered (so filtering 2nd item of [1,2,3] will give [1,2] )
Also I'm a bit tentative about instantiation. create_from
has filter as optional param. So also intended for copy. And copy would probably assume copying of attrs like mapper and keep_order ... and it does not because the source is the interface not the class ... so ... it might be misleading, maybe it should be just create_filtered
with mandatory filyer param. Or, maybe it should be a method of ajson interface ... which makes sense ... but then interfaces will be cross dependent ...
@larshp
v1.1.1-beta published. Please mind that it has a beta status. I'm still doubtful about create_from
semantics above. BTW would appreciate your opinion @larshp ( create_from
vs create_filtered
vs zif_ajson->filter
)
Can be closed ? Seems to be implemented by now