@SuppressLint("Assert") @Test public void testExperienceRoundTrip() throws IOException { final Experience experience = new Experience(); final Action action = new Action(); experience.getActions().add(action); final Gson gson = ExperienceParser.createGson(null); final String json1 = gson.toJson(experience); final Experience parsed = gson.fromJson(json1, Experience.class); final String json2 = gson.toJson(parsed); assert json1.equals(json2); }
public static Gson createGson(Context context) { if (gson == null) { GsonBuilder builder = new GsonBuilder(); if (context == null || Feature.get(context, R.bool.feature_load_old_experiences).isEnabled()) { builder.registerTypeAdapterFactory(new ExperienceTypeAdapterFactor()); } gson = builder.create(); } return gson; }
ExperienceParser { public static Gson createGson(Context context) { if (gson == null) { GsonBuilder builder = new GsonBuilder(); if (context == null || Feature.get(context, R.bool.feature_load_old_experiences).isEnabled()) { builder.registerTypeAdapterFactory(new ExperienceTypeAdapterFactor()); } gson = builder.create(); } return gson; } }
ExperienceParser { public static Gson createGson(Context context) { if (gson == null) { GsonBuilder builder = new GsonBuilder(); if (context == null || Feature.get(context, R.bool.feature_load_old_experiences).isEnabled()) { builder.registerTypeAdapterFactory(new ExperienceTypeAdapterFactor()); } gson = builder.create(); } return gson; }  }
ExperienceParser { public static Gson createGson(Context context) { if (gson == null) { GsonBuilder builder = new GsonBuilder(); if (context == null || Feature.get(context, R.bool.feature_load_old_experiences).isEnabled()) { builder.registerTypeAdapterFactory(new ExperienceTypeAdapterFactor()); } gson = builder.create(); } return gson; }  static Gson createGson(Context context); }
ExperienceParser { public static Gson createGson(Context context) { if (gson == null) { GsonBuilder builder = new GsonBuilder(); if (context == null || Feature.get(context, R.bool.feature_load_old_experiences).isEnabled()) { builder.registerTypeAdapterFactory(new ExperienceTypeAdapterFactor()); } gson = builder.create(); } return gson; }  static Gson createGson(Context context);  }