Why don't you just use TypeReference ?
For example...
Json file test.json in /your/path/ :
[{"s":"blah"},{"s":"baz"}]
The main class in the test package:
public class Main { public static void main(String[] args) { ObjectMapper mapper = new ObjectMapper(); try { List<IBar> actuallyFoos = mapper.readValue( new File("/your/path/test.json"), new TypeReference<List<Foo>>() { }); for (IBar ibar : actuallyFoos) { System.out.println(ibar.getClass()); } } catch (Throwable t) { t.printStackTrace(); } } static interface IBar { public String getS(); public void setS(String s); } static class Foo implements IBar { protected String s; public String getS() { return s; } public void setS(String s) { this.s = s; } } static class Bar implements IBar { protected String s; public String getS() { return s; } public void setS(String s) { this.s = s; } } }
The output of the main method:
class test.Main$Foo class test.Main$Foo
source share