Basically as above.
Gson gson = new Gson();
ErrorsDocument er = ErrorsDocument.Factory.newInstance();
er.setError("monkey escaped");
System.out.println(gson.toJson(er));
cra开发者_高级运维ps out with:
Exception in thread "main" java.lang.IllegalStateException: How can the type variable not be present in the class declaration! at com.google.gson.TypeInfoFactory.getIndex(TypeInfoFactory.java:127) at com.google.gson.TypeInfoFactory.getActualType(TypeInfoFactory.java:93) at com.google.gson.TypeInfoFactory.getTypeInfoForField(TypeInfoFactory.java:54)
etc
精彩评论