Limiting object depth and collection length during serialization for 3rd party classes

1,244 views
Skip to first unread message

ni...@codenation.co.in

unread,
Mar 15, 2017, 4:12:18 PM3/15/17
to jackson-user
While serializing an Object to JSON, how can I limit / put a threshold on:
1. The depth/nesting of objects (i.e. serialize up to 'n' levels only)
2. Size of collections (i.e. serialize only 'n' number of items of the collection)

I'm searching for a solution that works for 3rd party classes (source code of classes not available). Deserializing the JSON back is not a concern, I'm only serializing them.
Using jackson-core, version 2.8.6

Tatu Saloranta

unread,
Mar 15, 2017, 4:15:06 PM3/15/17
to jackson-user
There is no such functionality available for either aspects.

First one is unlikely to be supported at all as the delegation means
that none of serializers is concerned with more than one level (or,
possibly another small fixed number considering wrapping for type id
handling, or "unwrapped" properties).

Second one isn't something for which there is specific support,
although theoretically it could perhaps be supported via annotations
(new property for `@JsonFormat`). But I do not recall this feature
having been requested previously so it's not being worked on.

-+ 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 jackson-user...@googlegroups.com.
> To post to this group, send email to jackso...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

ni...@codenation.co.in

unread,
Mar 16, 2017, 12:40:34 AM3/16/17
to jackson-user
Thanks for the quick reply. Are there workarounds to implement these?

Tatu Saloranta

unread,
Mar 20, 2017, 2:19:11 PM3/20/17
to jackson-user
I hope someone who has had similar issue can share how they
implemented limitations.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages