public class MyClass<T>{ private T result; @JsonCreator // 重要註解,指定反序列化的構造函數 MyClass(@JsonProperty("result") T result){ this.result = result; } public T getResult(){ return this.result; } } ObjectMapper om = new ObjectMapper(); // 泛型實例化爲Class1 MyClas myClass1 = om.readValue(json, new TypeReference<MyClass<Class1>>(){}); // 泛型實例化爲Class2 MyClas myClass2 = om.readValue(json, new TypeReference<MyClass<Class2>>(){});