GSON on Google App Engine throws a Security Exception

后端 未结 4 622
忘掉有多难
忘掉有多难 2020-12-18 00:24

I am trying to convert an object into JSON using the GSON library on Google App Engine. For some reason, it throws this exception and I don\'t understand how to solve this.

4条回答
  •  独厮守ぢ
    2020-12-18 01:02

    You can construct GsonBuilder with .excludeFieldsWithoutExposeAnnotation(), and mark all serialized fields with @Expose annotation. In this case, Gson doesn't try to serialize fields other that you want.

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.excludeFieldsWithoutExposeAnnotation();
    String json = gsonBuilder.create().toJson(modelObject);
    

提交回复
热议问题