类 AbstractJsonMarshalTester<T>
java.lang.Object
org.springframework.boot.test.json.AbstractJsonMarshalTester<T>
- 类型参数:
T
- the type under test
- 直接已知子类:
GsonTester
,JacksonTester
,JsonbTester
Base class for AssertJ based JSON marshal testers. Exposes specific Asserts following a
read
, write
or parse
of JSON content. Typically used in
combination with an AssertJ assertThat
call. 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 see
JsonContentAssert
and
ObjectContentAssert
.
To use this library JSONAssert must be on the test classpath.
- 从以下版本开始:
- 1.4.0
- 作者:
- Phillip Webb
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明protected static class
Utility class used to support field initialization. -
构造器概要
构造器限定符构造器说明protected
Create a new uninitializedAbstractJsonMarshalTester
instance.AbstractJsonMarshalTester
(Class<?> resourceLoadClass, ResolvableType type) Create a newAbstractJsonMarshalTester
instance. -
方法概要
修饰符和类型方法说明protected JsonContent
<T> getJsonContent
(String json) Factory method used to get aJsonContent
instance from a source JSON string.protected final Class
<?> Return class used to load relative resources.protected final ResolvableType
getType()
Return the type under test.protected final void
initialize
(Class<?> resourceLoadClass, ResolvableType type) Initialize the marshal tester for use.parse
(byte[] jsonBytes) ReturnObjectContent
from parsing the specific JSON bytes.ReturnObjectContent
from parsing the specific JSON String.parseObject
(byte[] jsonBytes) Return the object created from parsing the specific JSON bytes.parseObject
(String jsonString) Return the object created from parsing the specific JSON String.ReturnObjectContent
from reading from the specified file.read
(InputStream inputStream) ReturnObjectContent
from reading from the specified input stream.ReturnObjectContent
from reading from the specified reader.ReturnObjectContent
from reading from the specified classpath resource.ReturnObjectContent
from reading from the specified resource.readObject
(File file) Return the object created from reading from the specified file.readObject
(InputStream inputStream) Return the object created from reading from the specified input stream.protected T
readObject
(InputStream inputStream, ResolvableType type) Read from the specified input stream to create an object of the specified type.readObject
(Reader reader) Return the object created from reading from the specified reader.protected abstract T
readObject
(Reader reader, ResolvableType type) Read from the specified reader to create an object of the specified type.readObject
(String resourcePath) Return the object created from reading from the specified classpath resource.readObject
(Resource resource) Return the object created from reading from the specified resource.ReturnJsonContent
from writing the specific value.protected abstract String
writeObject
(T value, ResolvableType type) Write the specified object to a JSON string.
-
构造器详细资料
-
AbstractJsonMarshalTester
protected AbstractJsonMarshalTester()Create a new uninitializedAbstractJsonMarshalTester
instance. -
AbstractJsonMarshalTester
Create a newAbstractJsonMarshalTester
instance.- 参数:
resourceLoadClass
- the source class used when loading relative classpath resourcestype
- the type under test
-
-
方法详细资料
-
initialize
Initialize the marshal tester for use.- 参数:
resourceLoadClass
- the source class used when loading relative classpath resourcestype
- the type under test
-
getType
Return the type under test.- 返回:
- the type under test
-
getResourceLoadClass
Return class used to load relative resources.- 返回:
- the resource load class
-
write
ReturnJsonContent
from writing the specific value.- 参数:
value
- the value to write- 返回:
- the
JsonContent
- 抛出:
IOException
- on write error
-
getJsonContent
Factory method used to get aJsonContent
instance from a source JSON string.- 参数:
json
- the source JSON- 返回:
- a new
JsonContent
instance - 从以下版本开始:
- 2.1.5
-
parseObject
Return the object created from parsing the specific JSON bytes.- 参数:
jsonBytes
- the source JSON bytes- 返回:
- the resulting object
- 抛出:
IOException
- on parse error
-
parse
ReturnObjectContent
from parsing the specific JSON bytes.- 参数:
jsonBytes
- the source JSON bytes- 返回:
- the
ObjectContent
- 抛出:
IOException
- on parse error
-
parseObject
Return the object created from parsing the specific JSON String.- 参数:
jsonString
- the source JSON string- 返回:
- the resulting object
- 抛出:
IOException
- on parse error
-
parse
ReturnObjectContent
from parsing the specific JSON String.- 参数:
jsonString
- the source JSON string- 返回:
- the
ObjectContent
- 抛出:
IOException
- on parse error
-
readObject
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 theresourceLoadClass
passed to the constructor- 返回:
- the resulting object
- 抛出:
IOException
- on read error
-
read
ReturnObjectContent
from reading from the specified classpath resource.- 参数:
resourcePath
- the source resource path. May be a full path or a path relative to theresourceLoadClass
passed to the constructor- 返回:
- the
ObjectContent
- 抛出:
IOException
- on read error
-
readObject
Return the object created from reading from the specified file.- 参数:
file
- the source file- 返回:
- the resulting object
- 抛出:
IOException
- on read error
-
read
ReturnObjectContent
from reading from the specified file.- 参数:
file
- the source file- 返回:
- the
ObjectContent
- 抛出:
IOException
- on read error
-
readObject
Return the object created from reading from the specified input stream.- 参数:
inputStream
- the source input stream- 返回:
- the resulting object
- 抛出:
IOException
- on read error
-
read
ReturnObjectContent
from reading from the specified input stream.- 参数:
inputStream
- the source input stream- 返回:
- the
ObjectContent
- 抛出:
IOException
- on read error
-
readObject
Return the object created from reading from the specified resource.- 参数:
resource
- the source resource- 返回:
- the resulting object
- 抛出:
IOException
- on read error
-
read
ReturnObjectContent
from reading from the specified resource.- 参数:
resource
- the source resource- 返回:
- the
ObjectContent
- 抛出:
IOException
- on read error
-
readObject
Return the object created from reading from the specified reader.- 参数:
reader
- the source reader- 返回:
- the resulting object
- 抛出:
IOException
- on read error
-
read
ReturnObjectContent
from reading from the specified reader.- 参数:
reader
- the source reader- 返回:
- the
ObjectContent
- 抛出:
IOException
- on read error
-
writeObject
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
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
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
-