类 AbstractJsonMarshalTester<T>
- java.lang.Object
 - org.springframework.boot.test.json.AbstractJsonMarshalTester<T>
 
- 类型参数:
 T- the type under test
- 直接已知子类:
 GsonTester,JacksonTester
public abstract class AbstractJsonMarshalTester<T> extends Object
Base class for AssertJ based JSON marshal testers. Exposes specific Asserts following aread,writeorparseof JSON content. Typically used in combination with an AssertJassertThatcall. For example:public class ExampleObjectJsonTests { private AbstractJsonTester<ExampleObject> json = //... @Test public void testWriteJson() { ExampleObject object = //... assertThat(json.write(object)).isEqualToJson("expected.json"); assertThat(json.read("expected.json")).isEqualTo(object); } }For a complete list of supported assertions seeJsonContentAssertandObjectContentAssert.To use this library JSONAssert must be on the test classpath.
- 从以下版本开始:
 - 1.4.0
 - 另请参阅:
 JsonContentAssert,ObjectContentAssert
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static classAbstractJsonMarshalTester.FieldInitializer<M>Utility class used to support field initialization.
构造器概要
构造器 限定符 构造器 说明 protectedAbstractJsonMarshalTester()Create a new uninitializedAbstractJsonMarshalTesterinstance.AbstractJsonMarshalTester(Class<?> resourceLoadClass, org.springframework.core.ResolvableType type)Create a newAbstractJsonMarshalTesterinstance.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected Class<?>getResourceLoadClass()Return class used to load relative resources.protected org.springframework.core.ResolvableTypegetType()Return the type under test.protected voidinitialize(Class<?> resourceLoadClass, org.springframework.core.ResolvableType type)Initialize the marshal tester for use.ObjectContent<T>parse(byte[] jsonBytes)ReturnObjectContentfrom parsing the specific JSON bytes.ObjectContent<T>parse(String jsonString)ReturnObjectContentfrom parsing the specific JSON String.TparseObject(byte[] jsonBytes)Return the object created from parsing the specific JSON bytes.TparseObject(String jsonString)Return the object created from parsing the specific JSON String.ObjectContent<T>read(File file)ReturnObjectContentfrom reading from the specified file.ObjectContent<T>read(InputStream inputStream)ReturnObjectContentfrom reading from the specified input stream.ObjectContent<T>read(Reader reader)ReturnObjectContentfrom reading from the specified reader.ObjectContent<T>read(String resourcePath)ReturnObjectContentfrom reading from the specified classpath resource.ObjectContent<T>read(org.springframework.core.io.Resource resource)ReturnObjectContentfrom reading from the specified resource.TreadObject(File file)Return the object created from reading from the specified file.TreadObject(InputStream inputStream)Return the object created from reading from the specified input stream.protected TreadObject(InputStream inputStream, org.springframework.core.ResolvableType type)Read from the specified input stream to create an object of the specified type.TreadObject(Reader reader)Return the object created from reading from the specified reader.protected abstract TreadObject(Reader reader, org.springframework.core.ResolvableType type)Read from the specified reader to create an object of the specified type.TreadObject(String resourcePath)Return the object created from reading from the specified classpath resource.TreadObject(org.springframework.core.io.Resource resource)Return the object created from reading from the specified resource.JsonContent<T>write(T value)ReturnJsonContentfrom writing the specific value.protected abstract StringwriteObject(T value, org.springframework.core.ResolvableType type)Write the specified object to a JSON string.
构造器详细资料
AbstractJsonMarshalTester
protected AbstractJsonMarshalTester()
Create a new uninitializedAbstractJsonMarshalTesterinstance.
AbstractJsonMarshalTester
public AbstractJsonMarshalTester(Class<?> resourceLoadClass, org.springframework.core.ResolvableType type)
Create a newAbstractJsonMarshalTesterinstance.- 参数:
 resourceLoadClass- the source class used when loading relative classpath resourcestype- the type under test
方法详细资料
initialize
protected final void initialize(Class<?> resourceLoadClass, org.springframework.core.ResolvableType type)
Initialize the marshal tester for use.- 参数:
 resourceLoadClass- the source class used when loading relative classpath resourcestype- the type under test
getType
protected final org.springframework.core.ResolvableType getType()
Return the type under test.- 返回:
 - the type under test
 
getResourceLoadClass
protected final Class<?> getResourceLoadClass()
Return class used to load relative resources.- 返回:
 - the resource load class
 
write
public JsonContent<T> write(T value) throws IOException
ReturnJsonContentfrom writing the specific value.- 参数:
 value- the value to write- 返回:
 - the 
JsonContent - 抛出:
 IOException- on write error
parseObject
public T parseObject(byte[] jsonBytes) throws IOException
Return the object created from parsing the specific JSON bytes.- 参数:
 jsonBytes- the source JSON bytes- 返回:
 - the resulting object
 - 抛出:
 IOException- on parse error
parse
public ObjectContent<T> parse(byte[] jsonBytes) throws IOException
ReturnObjectContentfrom parsing the specific JSON bytes.- 参数:
 jsonBytes- the source JSON bytes- 返回:
 - the 
ObjectContent - 抛出:
 IOException- on parse error
parseObject
public T parseObject(String jsonString) throws IOException
Return the object created from parsing the specific JSON String.- 参数:
 jsonString- the source JSON string- 返回:
 - the resulting object
 - 抛出:
 IOException- on parse error
parse
public ObjectContent<T> parse(String jsonString) throws IOException
ReturnObjectContentfrom parsing the specific JSON String.- 参数:
 jsonString- the source JSON string- 返回:
 - the 
ObjectContent - 抛出:
 IOException- on parse error
readObject
public T readObject(String resourcePath) throws IOException
Return the object created from reading from the specified classpath resource.- 参数:
 resourcePath- the source resource path. May be a full path or a path relative to theresourceLoadClasspassed to the constructor- 返回:
 - the resulting object
 - 抛出:
 IOException- on read error
read
public ObjectContent<T> read(String resourcePath) throws IOException
ReturnObjectContentfrom reading from the specified classpath resource.- 参数:
 resourcePath- the source resource path. May be a full path or a path relative to theresourceLoadClasspassed to the constructor- 返回:
 - the 
ObjectContent - 抛出:
 IOException- on read error
readObject
public T readObject(File file) throws IOException
Return the object created from reading from the specified file.- 参数:
 file- the source file- 返回:
 - the resulting object
 - 抛出:
 IOException- on read error
read
public ObjectContent<T> read(File file) throws IOException
ReturnObjectContentfrom reading from the specified file.- 参数:
 file- the source file- 返回:
 - the 
ObjectContent - 抛出:
 IOException- on read error
readObject
public T readObject(InputStream inputStream) throws IOException
Return the object created from reading from the specified input stream.- 参数:
 inputStream- the source input stream- 返回:
 - the resulting object
 - 抛出:
 IOException- on read error
read
public ObjectContent<T> read(InputStream inputStream) throws IOException
ReturnObjectContentfrom reading from the specified input stream.- 参数:
 inputStream- the source input stream- 返回:
 - the 
ObjectContent - 抛出:
 IOException- on read error
readObject
public T readObject(org.springframework.core.io.Resource resource) throws IOException
Return the object created from reading from the specified resource.- 参数:
 resource- the source resource- 返回:
 - the resulting object
 - 抛出:
 IOException- on read error
read
public ObjectContent<T> read(org.springframework.core.io.Resource resource) throws IOException
ReturnObjectContentfrom reading from the specified resource.- 参数:
 resource- the source resource- 返回:
 - the 
ObjectContent - 抛出:
 IOException- on read error
readObject
public T readObject(Reader reader) throws IOException
Return the object created from reading from the specified reader.- 参数:
 reader- the source reader- 返回:
 - the resulting object
 - 抛出:
 IOException- on read error
read
public ObjectContent<T> read(Reader reader) throws IOException
ReturnObjectContentfrom reading from the specified reader.- 参数:
 reader- the source reader- 返回:
 - the 
ObjectContent - 抛出:
 IOException- on read error
writeObject
protected abstract String writeObject(T value, org.springframework.core.ResolvableType type) throws IOException
Write the specified object to a JSON string.- 参数:
 value- the source value (nevernull)type- the resulting type (nevernull)- 返回:
 - the JSON string
 - 抛出:
 IOException- on write error
readObject
protected T readObject(InputStream inputStream, org.springframework.core.ResolvableType type) throws IOException
Read from the specified input stream to create an object of the specified type. The default implementation delegates toreadObject(Reader, ResolvableType).- 参数:
 inputStream- the source input stream (nevernull)type- the resulting type (nevernull)- 返回:
 - the resulting object
 - 抛出:
 IOException- on read error
readObject
protected abstract T readObject(Reader reader, org.springframework.core.ResolvableType type) throws IOException
Read from the specified reader to create an object of the specified type.- 参数:
 reader- the source reader (nevernull)type- the resulting type (nevernull)- 返回:
 - the resulting object
 - 抛出:
 IOException- on read error