Jackson: deserialize array of Strings to List<T>

Viewed 11441

For a JSON object, Subject:

{ 
    "permissions":["foo", "bar"],
    ...
}

... I would like to deserialize to:

class Subject {
    private List<Permission> permissions;
    ...

... where Permission is:

class Permission {
    ....
    public Permission(String permission) {
    ....
    }

Permission is not a class I control, so I only have the constructor to deal with.

I'm certain Jackson can do this but I'm just not convinced I have found the best way yet. My efforts with ArrayDeserializer and @JsonDeserialize(contentAs = Permission.class) have failed and before I start subclassing a JsonDeserializer I want to verify that no built in functionality can do this.

2 Answers
Related