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
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
- 
Nested Class SummaryNested classes/interfaces inherited from class AbstractJsonMarshalTesterAbstractJsonMarshalTester.FieldInitializer<M>
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedGsonTester(com.google.gson.Gson gson) Create a new uninitializedGsonTesterinstance.GsonTester(Class<?> resourceLoadClass, ResolvableType type, com.google.gson.Gson gson) Create a newGsonTesterinstance.
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidinitFields(Object testInstance, com.google.gson.Gson gson) Utility method to initializeGsonTesterfields.static voidinitFields(Object testInstance, ObjectFactory<com.google.gson.Gson> gson) Utility method to initializeGsonTesterfields.protected TreadObject(Reader reader, ResolvableType type) Read from the specified reader to create an object of the specified type.protected StringwriteObject(T value, ResolvableType type) Write the specified object to a JSON string.Methods inherited from class AbstractJsonMarshalTestergetJsonContent, getResourceLoadClass, getType, initialize, parse, parse, parseObject, parseObject, read, read, read, read, read, readObject, readObject, readObject, readObject, readObject, readObject, write
- 
Constructor Details- 
GsonTesterprotected GsonTester(com.google.gson.Gson gson) Create a new uninitializedGsonTesterinstance.- Parameters:
- gson- the Gson instance
 
- 
GsonTesterCreate a newGsonTesterinstance.- Parameters:
- resourceLoadClass- the source class used to load resources
- type- the type under test
- gson- the Gson instance
- See Also:
 
 
- 
- 
Method Details- 
writeObjectDescription copied from class:AbstractJsonMarshalTesterWrite the specified object to a JSON string.- Specified by:
- writeObjectin class- AbstractJsonMarshalTester<T>
- Parameters:
- value- the source value (never- null)
- type- the resulting type (never- null)
- Returns:
- the JSON string
- Throws:
- IOException- on write error
 
- 
readObjectDescription copied from class:AbstractJsonMarshalTesterRead from the specified reader to create an object of the specified type.- Specified by:
- readObjectin class- AbstractJsonMarshalTester<T>
- Parameters:
- reader- the source reader (never- null)
- type- the resulting type (never- null)
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
- 
initFieldsUtility method to initializeGsonTesterfields. Seeclass-level documentationfor example usage.- Parameters:
- testInstance- the test instance
- gson- the Gson instance
 
- 
initFieldsUtility method to initializeGsonTesterfields. Seeclass-level documentationfor example usage.- Parameters:
- testInstance- the test instance
- gson- an object factory to create the Gson instance
 
 
-