类 JacksonTester<T>
java.lang.Object
org.springframework.boot.test.json.AbstractJsonMarshalTester<T>
org.springframework.boot.test.json.JacksonTester<T>
- 类型参数:
T- the type under test
AssertJ based JSON tester backed by Jackson. Usually instantiated via
initFields(Object, ObjectMapper), for example:
public class ExampleObjectJsonTests {
private JacksonTester<ExampleObject> json;
@Before
public void setup() {
ObjectMapper objectMapper = new ObjectMapper();
JacksonTester.initFields(this, objectMapper);
}
@Test
public void testWriteJson() throws IOException {
ExampleObject object = //...
assertThat(json.write(object)).isEqualToJson("expected.json");
}
}
See AbstractJsonMarshalTester for more details.- 从以下版本开始:
- 1.4.0
- 作者:
- Phillip Webb, Madhura Bhave, Diego Berrueta
-
嵌套类概要
从类继承的嵌套类/接口 org.springframework.boot.test.json.AbstractJsonMarshalTester
AbstractJsonMarshalTester.FieldInitializer<M> -
构造器概要
构造器限定符构造器说明protectedJacksonTester(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJacksonTesterinstance.JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJacksonTesterinstance.JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<?> view) -
方法概要
修饰符和类型方法说明Returns a new instance ofJacksonTesterwith the view that should be used for json serialization/deserialization.protected JsonContent<T> getJsonContent(String json) Factory method used to get aJsonContentinstance from a source JSON string.static voidinitFields(Object testInstance, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Utility method to initializeJacksonTesterfields.static voidinitFields(Object testInstance, ObjectFactory<com.fasterxml.jackson.databind.ObjectMapper> objectMapperFactory) Utility method to initializeJacksonTesterfields.protected TreadObject(InputStream inputStream, ResolvableType type) Read from the specified input stream to create an object of the specified type.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.从类继承的方法 org.springframework.boot.test.json.AbstractJsonMarshalTester
getResourceLoadClass, getType, initialize, parse, parse, parseObject, parseObject, read, read, read, read, read, readObject, readObject, readObject, readObject, readObject, write
-
构造器详细资料
-
JacksonTester
protected JacksonTester(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJacksonTesterinstance.- 参数:
objectMapper- the Jackson object mapper
-
JacksonTester
public JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Create a newJacksonTesterinstance.- 参数:
resourceLoadClass- the source class used to load resourcestype- the type under testobjectMapper- the Jackson object mapper
-
JacksonTester
public JacksonTester(Class<?> resourceLoadClass, ResolvableType type, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<?> view)
-
-
方法详细资料
-
getJsonContent
从类复制的说明:AbstractJsonMarshalTesterFactory method used to get aJsonContentinstance from a source JSON string.- 覆盖:
getJsonContent在类中AbstractJsonMarshalTester<T>- 参数:
json- the source JSON- 返回:
- a new
JsonContentinstance
-
readObject
从类复制的说明:AbstractJsonMarshalTesterRead from the specified input stream to create an object of the specified type. The default implementation delegates toAbstractJsonMarshalTester.readObject(Reader, ResolvableType).- 覆盖:
readObject在类中AbstractJsonMarshalTester<T>- 参数:
inputStream- the source input stream (nevernull)type- the resulting type (nevernull)- 返回:
- the resulting object
- 抛出:
IOException- on read error
-
readObject
从类复制的说明:AbstractJsonMarshalTesterRead 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
-
writeObject
从类复制的说明:AbstractJsonMarshalTesterWrite 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
-
initFields
public static void initFields(Object testInstance, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Utility method to initializeJacksonTesterfields. Seeclass-level documentationfor example usage.- 参数:
testInstance- the test instanceobjectMapper- the object mapper- 另请参阅:
-
initFields
public static void initFields(Object testInstance, ObjectFactory<com.fasterxml.jackson.databind.ObjectMapper> objectMapperFactory) Utility method to initializeJacksonTesterfields. Seeclass-level documentationfor example usage.- 参数:
testInstance- the test instanceobjectMapperFactory- a factory to create the object mapper- 另请参阅:
-
forView
Returns a new instance ofJacksonTesterwith the view that should be used for json serialization/deserialization.- 参数:
view- the view class- 返回:
- the new instance
-