Class GsonTester<T>

java.lang.Object
org.springframework.boot.test.json.AbstractJsonMarshalTester<T>
org.springframework.boot.test.json.GsonTester<T>
Type Parameters:
T - the type under test

public class GsonTester<T> extends AbstractJsonMarshalTester<T>
AssertJ based JSON tester backed by Gson. Usually instantiated via initFields(Object, Gson), for example:
 public class ExampleObjectJsonTests {

     private GsonTester<ExampleObject> json;

     @Before
     public void setup() {
         Gson gson = new GsonBuilder().create();
         GsonTester.initFields(this, gson);
     }

     @Test
     public void testWriteJson() throws IOException {
         ExampleObject object = //...
         assertThat(json.write(object)).isEqualToJson("expected.json");
     }

 }
 
See AbstractJsonMarshalTester for more details.
Since:
1.4.0
Author:
Phillip Webb
  • Constructor Details

    • GsonTester

      protected GsonTester(com.google.gson.Gson gson)
      Create a new uninitialized GsonTester instance.
      Parameters:
      gson - the Gson instance
    • GsonTester

      public GsonTester(Class<?> resourceLoadClass, ResolvableType type, com.google.gson.Gson gson)
      Create a new GsonTester instance.
      Parameters:
      resourceLoadClass - the source class used to load resources
      type - the type under test
      gson - the Gson instance
      See Also:
  • Method Details