I'm writing a subclass extends ArrayList, and then use JSON to 'encode' it. However, the new class fields are missing in the output
@Data
public static class NewArray<T> extends ArrayList<T> {
private String testField;
public NewArray(Collection<T> c, String msg) {
super(c);
testField = msg;
}
}
Gson gson = new GsonBuilder().create();
List<Integer> input = Lists.newArrayList(111, 222);
NewArray n = new NewArray(input, "test field");
System.out.println(gson.toJson(n))
The output is:
[111,222]
No testField
output
What am I missing here?
Should I use combination instead?