类 GsonTester<T>
- java.lang.Object
- org.springframework.boot.test.json.AbstractJsonMarshalTester<T>
- org.springframework.boot.test.json.GsonTester<T>
- 类型参数:
T
- the type under test
public class GsonTester<T> extends AbstractJsonMarshalTester<T>
AssertJ based JSON tester backed by Gson. Usually instantiated viainitFields(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"); } }
SeeAbstractJsonMarshalTester
for more details.- 从以下版本开始:
- 1.4.0
嵌套类概要
从类继承的嵌套类/接口 org.springframework.boot.test.json.AbstractJsonMarshalTester
AbstractJsonMarshalTester.FieldInitializer<M>
构造器概要
构造器 限定符 构造器 说明 protected
GsonTester(com.google.gson.Gson gson)
Create a new uninitializedGsonTester
instance.GsonTester(Class<?> resourceLoadClass, org.springframework.core.ResolvableType type, com.google.gson.Gson gson)
Create a newGsonTester
instance.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static void
initFields(Object testInstance, com.google.gson.Gson gson)
Utility method to initializeGsonTester
fields.static void
initFields(Object testInstance, org.springframework.beans.factory.ObjectFactory<com.google.gson.Gson> gson)
Utility method to initializeGsonTester
fields.protected T
readObject(Reader reader, org.springframework.core.ResolvableType type)
Read from the specified reader to create an object of the specified type.protected String
writeObject(T value, org.springframework.core.ResolvableType type)
Write the specified object to a JSON string.从类继承的方法 org.springframework.boot.test.json.AbstractJsonMarshalTester
getResourceLoadClass, getType, initialize, parse, parse, parseObject, parseObject, read, read, read, read, read, readObject, readObject, readObject, readObject, readObject, readObject, write
构造器详细资料
GsonTester
protected GsonTester(com.google.gson.Gson gson)
Create a new uninitializedGsonTester
instance.- 参数:
gson
- the Gson instance
GsonTester
public GsonTester(Class<?> resourceLoadClass, org.springframework.core.ResolvableType type, com.google.gson.Gson gson)
Create a newGsonTester
instance.- 参数:
resourceLoadClass
- the source class used to load resourcestype
- the type under testgson
- the Gson instance- 另请参阅:
initFields(Object, Gson)
方法详细资料
writeObject
protected String writeObject(T value, org.springframework.core.ResolvableType type) throws IOException
从类复制的说明:AbstractJsonMarshalTester
Write the specified object to a JSON string.- 指定者:
writeObject
在类中AbstractJsonMarshalTester<T>
- 参数:
value
- the source value (nevernull
)type
- the resulting type (nevernull
)- 返回:
- the JSON string
- 抛出:
IOException
- on write error
readObject
protected T readObject(Reader reader, org.springframework.core.ResolvableType type) throws IOException
从类复制的说明:AbstractJsonMarshalTester
Read from the specified reader to create an object of the specified type.- 指定者:
readObject
在类中AbstractJsonMarshalTester<T>
- 参数:
reader
- the source reader (nevernull
)type
- the resulting type (nevernull
)- 返回:
- the resulting object
- 抛出:
IOException
- on read error
initFields
public static void initFields(Object testInstance, com.google.gson.Gson gson)
Utility method to initializeGsonTester
fields. Seeclass-level documentation
for example usage.- 参数:
testInstance
- the test instancegson
- the Gson instance
initFields
public static void initFields(Object testInstance, org.springframework.beans.factory.ObjectFactory<com.google.gson.Gson> gson)
Utility method to initializeGsonTester
fields. Seeclass-level documentation
for example usage.- 参数:
testInstance
- the test instancegson
- an object factory to create the Gson instance