/v3.2/nimbits-sdk/src/com/nimbits/gson/GsonFactory.java

http://nimbits-server.googlecode.com/ · Java · 54 lines · 30 code · 6 blank · 18 comment · 2 complexity · 10e5f72f707f9e68cde2fd6c80476949 MD5 · raw file

  1. /*
  2. * Copyright (c) 2010 Tonic Solutions LLC.
  3. *
  4. * http://www.nimbits.com
  5. *
  6. *
  7. * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * http://www.gnu.org/licenses/gpl.html
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  12. */
  13. package com.nimbits.gson;
  14. import com.google.gson.Gson;
  15. import com.google.gson.GsonBuilder;
  16. import com.google.gson.reflect.*;
  17. import com.nimbits.client.model.Const;
  18. import com.nimbits.client.model.category.impl.*;
  19. import com.nimbits.client.model.diagram.*;
  20. import com.nimbits.client.model.point.*;
  21. import com.nimbits.client.model.user.*;
  22. import com.nimbits.client.model.value.*;
  23. import java.lang.reflect.*;
  24. import java.util.*;
  25. /**
  26. * Created by bsautner
  27. * User: benjamin
  28. * Date: 8/3/11
  29. * Time: 8:39 PM
  30. */
  31. public class GsonFactory {
  32. private static Gson instance;
  33. public final static Type categoryListType = new TypeToken<List<PointCategoryModelImpl>>() {}.getType();
  34. public final static Type pointListType = new TypeToken<List<PointModel>>() {}.getType();
  35. public final static Type diagramListType = new TypeToken<List<DiagramModel>>() {}.getType();
  36. public final static Type userListType = new TypeToken<List<UserModel>>() {}.getType();
  37. public final static Type valueListType = new TypeToken<List<ValueModel>>() {}.getType();
  38. private GsonFactory() {
  39. throw new AssertionError();
  40. }
  41. public static Gson getInstance() {
  42. if (instance == null)
  43. {
  44. instance = new GsonBuilder().setDateFormat(Const.GSON_DATE_FORMAT).serializeNulls().create();
  45. }
  46. return instance;
  47. }
  48. }