FasterXML / jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Apache License 2.0
3.52k stars 1.38k forks source link

Support deserializing Iterable #199

Closed electrum closed 11 years ago

electrum commented 11 years ago

I often have a class like this:

public class Results {
    private final Iterable<String> data;

    @JsonCreator
    public Results(@JsonProperty("data") Iterable<String> data) {
        this.data = Iterables.unmodifiableIterable(data);
    }

    @JsonProperty
    public Iterable<String> getData() {
        return data;
    }
}

This class takes an iterable when used for serialization, because this allows streaming serialization if the underlying data source is iterable.

When deserializing, Jackson should be smart enough to deserialize this as a List (or any ordered Iterable type). I shouldn't have to write a separate constructor that takes a List or write a bunch of code to register a custom deserializer mapping.

cowtowncoder commented 11 years ago

This would make sense, when the thing is specifically declared as Iterable. I think most concerns would be for other kinds of cases, for serialization (where Iterable tends to be implemented as secondary trait, and not always be the interface to use).

Help would be appreciated, we defnitely want to support this.

cowtowncoder commented 11 years ago

Spend some time figuring out how to do it, added support, will be in 2.2.