Skip to content

Conversation

avlo
Copy link
Collaborator

@avlo avlo commented Dec 26, 2024

hi, eric. re: REQ custom filters (like "#g", "#d", #<any_single_character>, etc) which currently do not function properly in Filters class (as its customTagQuery field key is literally the fixed value #customTagQuery):

i'd tried several techniques to achieve #<any_single_character> filter using dynamically defined JSON keys with existing CustomGenericTagQueryListDeserializer (& several attempted variants of it) also with & without CustomFiltersListDeserializer (several attempted variants of it as well)- operating on a CustomTagQuery object- yet unfortunately all have been unsuccessful thus far.

in the meanwhile, this PR is a functioning alternate implementation whereby defined JSON Filters keys customTagQuery field in Filters have been changed from type CustomTagQuery to Map<String, String> using jackson dynamic object mapping (see links below) functioning as expected for relevant classes:

Filters
List<Filters>
customTagQuery (itself now a Map)
list of customTagQuery (now as a List<Map>)

all of which are demonstrated & functioning as expected in JsonParseTest.

per your interest/consideration, a few thoughts as follows:

  1. run this PR by you in the event you might be able to refactor its functionality using GenericTagQuery as an object rather than my Map<String, String> implementation.

  2. if you haven't a solution for the above, and assuming unit/integration tests complete successfully against your nostr relay variant, consider this PR for your eval/comment/approval/etc so that nostr-java (and superconductor) can both minimally support custom REQ filters.

note: now that serialization/deserialization is handled using Map<String, String> & the jackson @JsonAnyGetter/@JsonAnyGetter annotations, previous custom serializer/deserializer implementations are rendered superfluous and have thus have been removed.

lmk if any questions/concerns/omissions/etc


useful/relevant jackson dynamic object mapping links:
https://www.geeksforgeeks.org/mapping-a-dynamic-json-object-field-in-jackson-with-java/
https://www.logicbig.com/tutorials/misc/jackson/jackson-any-setter.html
https://www.baeldung.com/jackson-mapping-dynamic-object#using-jsonanysetter

avlo added 6 commits December 24, 2024 18:32
… & @JsonAnySetter via Map<String, Object>

GenericTagQuery usages replaced with Map<String, Object>
Filters now use @JsonAnyGetter & @JsonAnySetter
FDecoder interface method decode() refactored to decode(String str)
FiltersDecoder refactored to FiltersDecoder<T extends Filters>, constructor json String parameter removed
CustomGenericTagQuerySerializer no longer necessary, removed
tests updated
@tcheeric
Copy link
Owner

tcheeric commented Jan 2, 2025

Hi Nick, seeing this only now. I am working on this. Thanks for this!

@avlo
Copy link
Collaborator Author

avlo commented Jan 2, 2025

Hi Nick, seeing this only now. I am working on this. Thanks for this!

yep, def no rush & thx as well 👍

@tcheeric tcheeric merged commit fa82fc3 into tcheeric:develop Jan 3, 2025
@tcheeric
Copy link
Owner

tcheeric commented Jan 3, 2025

Thanks, Nick. Glad to see you tackled this. GTQ had been a major headache for me.

@avlo
Copy link
Collaborator Author

avlo commented Jan 3, 2025

yw & btw, i def preferred your CustomTagQuery object design/approach and will be thinking about an easy/intuitive means of getting it- along with its intended dynamic JSON keys (+ serial/deserial) back into the framework (rather than my Map<String, String> implementation) and will keep you posted.

@avlo avlo deleted the generictagquery_decoder_deserializer-using_jackson branch January 3, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants