Is it OK to use Gson instance as a static field in a model bean (reuse)?

前端 未结 4 1171
逝去的感伤
逝去的感伤 2020-11-29 02:44

Here\'s the model I implemented:

public class LoginSession {
    private static final Gson gson = new Gson();

    private String id;
    private String name         


        
4条回答
  •  有刺的猬
    2020-11-29 03:07

    We had issues with thread safety a while back and we solved it by using the FastDateFormat in apache commons.

    Just created a gist Link for Gist around this to help the people wondering if Gson instances can be reused. They do not have setters and all vars are private.

    So other than the SimpleDateFormat issue I don't see them maintaining state anywhere else.

    Do check it out. This is my first time replying to one of these . Happy to give back for once . :)

提交回复
热议问题