XStream Serialization: SortedSet vs. NavigableSet vs. TreeSet

56 views
Skip to first unread message

Ullrich Hafner

unread,
Oct 17, 2022, 5:43:19 AM10/17/22
to JenkinsCI Developers
In one of my serialized instances I am using a TreeSet to store some properties.

When I declare the Java field as SortedSet (interface) or TreeSet (class), the Jenkins XStream correctly serializes the model. However, when I declare my field as NavigableSet (interface), then the serialization resolves the field to null.

Shouldn’t XStream always pick the correct dynamic type (and not the static type) when serializing things? Or did we specify a specific converter that uses a static type?

Jesse Glick

unread,
Oct 17, 2022, 7:42:27 AM10/17/22
to jenkin...@googlegroups.com
On Mon, Oct 17, 2022 at 5:43 AM Ullrich Hafner <ullrich...@gmail.com> wrote:
Shouldn’t XStream always pick the correct dynamic type (and not the static type) when serializing things?

As far as I know it does, but then again the representation for exotic collection types is complex.

You should declare the persisted field to be of some simpler type, preferably `ArrayList`. If you need to enforce uniqueness, sorting, etc. in memory during operations, do so using any other mechanism, perhaps a `transient` field. 
Reply all
Reply to author
Forward
0 new messages