On Fri, Jan 10, 2020 at 1:14 PM Volkan Yazıcı <[email protected]>
wrote:

> I have a bunch of POJOs deserialized from JSON strings. Is it possible to
> instruct Jackson at runtime to indicate which fields need to be
> deserialized? Consider the following POJO structure rooted at A:
>
> class A {
>     String a1;
>     String a2;
>     String a3;
>     B b;
> }
>
> class B {
>     String b1;
>     String b2;
>     C c;
> }
>
> class C {
>     String c1;
>     String c2;
> }
>
> At compile time I can generate 2^4 * 2^3 * 2^2 view classes to achieve
> what I want, but that sounds like an overkill. Is there simpler way to
> achieve this?
>
>
If this was about serialization, there are a few mechanism to do filtering
dynamically, but for deserialization there's just JSON Views, and then
streaming-level `FilteringParserDelegate` which could probably work but is
some work to use.
Specific mechanism from serialization side that would be nice is JSON
Filters (`@JsonFilter`), but unfortunately databind-side abstraction is
serialization-specific (uses delegation, wherein filter calls write methods
on things to pass).

I think what most developers do is to serialize/convert to an intermediate
structure (JsonNode, Map), then filter out things they don't want, and then
serialize that pruned version as JSON.

-+ Tatu +-

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAGrxA24X8Qq52acgBybbZdFbjq4ywnNpKVvfD3NQng5UNE60Yg%40mail.gmail.com.

Reply via email to