On Tue, Sep 19, 2023 at 10:31 AM Dai MIKURUBE <
dmik...@acm.org> wrote:
>
> Hi,
>
> I have a sequence of multiple JSONs in a stream, and wanted to filter the sequence by FilteringParserDelegate / JsonPointerBasedFilter.
>
> It works in normal matching cases. But, I wanted to raise an error when a matching property does not exist.
Sounds reasonable.
>
> For example, in the following case :
>
> JsonParser parser = new FilteringParserDelegate(
> factory.createParser("{\"foo\":{\"bar\":\"baz\"}}{\"xxx\":{\"yyy\":\"zzz\"}}{\"foo\":{\"bar\":\"qux\"}}"),
> new JsonPointerBasedFilter("/foo"),
> TokenFilter.Inclusion.ONLY_INCLUDE_ALL,
> true
> );
>
> This |parser| returns {"bar":"baz"}, and {"bar":"qux"}, with just skipping {"xxx":{"yyy":"zzz"}}.
>
> Here, I wanted to raise an error (Exception) while reading {"xxx":{"yyy":"zzz"}}.
>
>
> Does anyone know how to realize it? I'm ready to write my own TokenFilter, or to expand JsonPointerBasedFilter by myself.
I haven't done this, but looking at `JsonPointerBasedFilter` I would
probably try overriding `includeProperty()` method to catch the case
of non-match. Note that you'd also need to override `includeElement`,
and for both make sure to construct an instance of your own sub-class.
I think that should allow you to do what you want.
I'll also file an issue for minor improvement for
`JsonPointerBasedFilter` to make sub-classing bit safer.
-+ Tatu +-
>
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
jackson-user...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/6acc6b25-7292-4b31-a08f-8f541a075158n%40googlegroups.com.