Class AbstractJsonMarshalTester<T>
java.lang.Object
org.springframework.boot.test.json.AbstractJsonMarshalTester<T>
- Type Parameters:
- T- the type under test
- Direct Known Subclasses:
- 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.
- Since:
- 1.4.0
- Author:
- Phillip Webb
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classUtility class used to support field initialization.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCreate a new uninitializedAbstractJsonMarshalTesterinstance.AbstractJsonMarshalTester(Class<?> resourceLoadClass, ResolvableType type) Create a newAbstractJsonMarshalTesterinstance.
- 
Method SummaryModifier and TypeMethodDescriptionprotected JsonContent<T>getJsonContent(String json) Factory method used to get aJsonContentinstance from a source JSON string.protected final Class<?>Return class used to load relative resources.protected final ResolvableTypegetType()Return the type under test.protected final voidinitialize(Class<?> resourceLoadClass, ResolvableType type) Initialize the marshal tester for use.parse(byte[] jsonBytes) ReturnObjectContentfrom parsing the specific JSON bytes.ReturnObjectContentfrom 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.ReturnObjectContentfrom reading from the specified file.read(InputStream inputStream) ReturnObjectContentfrom reading from the specified input stream.ReturnObjectContentfrom reading from the specified reader.ReturnObjectContentfrom reading from the specified classpath resource.ReturnObjectContentfrom 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 TreadObject(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 TreadObject(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.ReturnJsonContentfrom writing the specific value.protected abstract StringwriteObject(T value, ResolvableType type) Write the specified object to a JSON string.
- 
Constructor Details- 
AbstractJsonMarshalTesterprotected AbstractJsonMarshalTester()Create a new uninitializedAbstractJsonMarshalTesterinstance.
- 
AbstractJsonMarshalTesterCreate a newAbstractJsonMarshalTesterinstance.- Parameters:
- resourceLoadClass- the source class used when loading relative classpath resources
- type- the type under test
 
 
- 
- 
Method Details- 
initializeInitialize the marshal tester for use.- Parameters:
- resourceLoadClass- the source class used when loading relative classpath resources
- type- the type under test
 
- 
getTypeReturn the type under test.- Returns:
- the type under test
 
- 
getResourceLoadClassReturn class used to load relative resources.- Returns:
- the resource load class
 
- 
writeReturnJsonContentfrom writing the specific value.- Parameters:
- value- the value to write
- Returns:
- the JsonContent
- Throws:
- IOException- on write error
 
- 
getJsonContentFactory method used to get aJsonContentinstance from a source JSON string.- Parameters:
- json- the source JSON
- Returns:
- a new JsonContentinstance
- Since:
- 2.1.5
 
- 
parseObjectReturn the object created from parsing the specific JSON bytes.- Parameters:
- jsonBytes- the source JSON bytes
- Returns:
- the resulting object
- Throws:
- IOException- on parse error
 
- 
parseReturnObjectContentfrom parsing the specific JSON bytes.- Parameters:
- jsonBytes- the source JSON bytes
- Returns:
- the ObjectContent
- Throws:
- IOException- on parse error
 
- 
parseObjectReturn the object created from parsing the specific JSON String.- Parameters:
- jsonString- the source JSON string
- Returns:
- the resulting object
- Throws:
- IOException- on parse error
 
- 
parseReturnObjectContentfrom parsing the specific JSON String.- Parameters:
- jsonString- the source JSON string
- Returns:
- the ObjectContent
- Throws:
- IOException- on parse error
 
- 
readObjectReturn the object created from reading from the specified classpath resource.- Parameters:
- resourcePath- the source resource path. May be a full path or a path relative to the- resourceLoadClasspassed to the constructor
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
- 
readReturnObjectContentfrom reading from the specified classpath resource.- Parameters:
- resourcePath- the source resource path. May be a full path or a path relative to the- resourceLoadClasspassed to the constructor
- Returns:
- the ObjectContent
- Throws:
- IOException- on read error
 
- 
readObjectReturn the object created from reading from the specified file.- Parameters:
- file- the source file
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
- 
readReturnObjectContentfrom reading from the specified file.- Parameters:
- file- the source file
- Returns:
- the ObjectContent
- Throws:
- IOException- on read error
 
- 
readObjectReturn the object created from reading from the specified input stream.- Parameters:
- inputStream- the source input stream
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
- 
readReturnObjectContentfrom reading from the specified input stream.- Parameters:
- inputStream- the source input stream
- Returns:
- the ObjectContent
- Throws:
- IOException- on read error
 
- 
readObjectReturn the object created from reading from the specified resource.- Parameters:
- resource- the source resource
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
- 
readReturnObjectContentfrom reading from the specified resource.- Parameters:
- resource- the source resource
- Returns:
- the ObjectContent
- Throws:
- IOException- on read error
 
- 
readObjectReturn the object created from reading from the specified reader.- Parameters:
- reader- the source reader
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
- 
readReturnObjectContentfrom reading from the specified reader.- Parameters:
- reader- the source reader
- Returns:
- the ObjectContent
- Throws:
- IOException- on read error
 
- 
writeObjectWrite the specified object to a JSON string.- Parameters:
- value- the source value (never- null)
- type- the resulting type (never- null)
- Returns:
- the JSON string
- Throws:
- IOException- on write error
 
- 
readObjectRead from the specified input stream to create an object of the specified type. The default implementation delegates toreadObject(Reader, ResolvableType).- Parameters:
- inputStream- the source input stream (never- null)
- type- the resulting type (never- null)
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
- 
readObjectRead from the specified reader to create an object of the specified type.- Parameters:
- reader- the source reader (never- null)
- type- the resulting type (never- null)
- Returns:
- the resulting object
- Throws:
- IOException- on read error
 
 
-