@Test public void test_using_gsonBuilder() { String expectedJson = "{\n" + " \"byteprimitive\": 0,\n" + " \"shortprimitive\": 0,\n" + " \"charprimitive\": \"\\u0000\",\n" + " \"intprimitive\": 0,\n" + " \"longprimitive\": 0,\n" + " \"floatprimitive\": 0.0,\n" + " \"doubleprimitive\": 0.0,\n" + " \"aboolean\": false,\n" + " \"bytewrapper\": 0,\n" + " \"shortwrapper\": 0,\n" + " \"charwrapper\": \"\\u0000\",\n" + " \"intwrapper\": 0,\n" + " \"longwrapper\": 0,\n" + " \"floatwrapper\": 0.0,\n" + " \"doublewrapper\": 0.0,\n" + " \"booleanwrapper\": false,\n" + " \"string\": \"Hello World\"\n" + "}"; String actualJson = RuntimeSampler.gsonBuilder().create().toJson(new AllBasicTypes()); String cc = RuntimeSampler.gsonBuilder().create().fromJson("", String.class); assertThat(actualJson).isEqualTo(expectedJson); }
public static GsonBuilder gsonBuilder() { return new GsonBuilder() .serializeNulls() .setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { return false; } @Override public boolean shouldSkipClass(Class<?> aClass) { return false; } }) .excludeFieldsWithModifiers(Modifier.PROTECTED) .excludeFieldsWithoutExposeAnnotation() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setFieldNamingStrategy((field) -> field.getName().toLowerCase()) .setDateFormat("MM/dd/yyyy") .setPrettyPrinting(); }
RuntimeSampler { public static GsonBuilder gsonBuilder() { return new GsonBuilder() .serializeNulls() .setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { return false; } @Override public boolean shouldSkipClass(Class<?> aClass) { return false; } }) .excludeFieldsWithModifiers(Modifier.PROTECTED) .excludeFieldsWithoutExposeAnnotation() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setFieldNamingStrategy((field) -> field.getName().toLowerCase()) .setDateFormat("MM/dd/yyyy") .setPrettyPrinting(); } }
RuntimeSampler { public static GsonBuilder gsonBuilder() { return new GsonBuilder() .serializeNulls() .setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { return false; } @Override public boolean shouldSkipClass(Class<?> aClass) { return false; } }) .excludeFieldsWithModifiers(Modifier.PROTECTED) .excludeFieldsWithoutExposeAnnotation() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setFieldNamingStrategy((field) -> field.getName().toLowerCase()) .setDateFormat("MM/dd/yyyy") .setPrettyPrinting(); }  }
RuntimeSampler { public static GsonBuilder gsonBuilder() { return new GsonBuilder() .serializeNulls() .setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { return false; } @Override public boolean shouldSkipClass(Class<?> aClass) { return false; } }) .excludeFieldsWithModifiers(Modifier.PROTECTED) .excludeFieldsWithoutExposeAnnotation() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setFieldNamingStrategy((field) -> field.getName().toLowerCase()) .setDateFormat("MM/dd/yyyy") .setPrettyPrinting(); }  static GsonBuilder gsonBuilder(); }
RuntimeSampler { public static GsonBuilder gsonBuilder() { return new GsonBuilder() .serializeNulls() .setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { return false; } @Override public boolean shouldSkipClass(Class<?> aClass) { return false; } }) .excludeFieldsWithModifiers(Modifier.PROTECTED) .excludeFieldsWithoutExposeAnnotation() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setFieldNamingStrategy((field) -> field.getName().toLowerCase()) .setDateFormat("MM/dd/yyyy") .setPrettyPrinting(); }  static GsonBuilder gsonBuilder();  }