Class BasicJsonTester
java.lang.Object
org.springframework.boot.test.json.BasicJsonTester
AssertJ based JSON tester that works with basic JSON strings. Allows testing of JSON
 payloads created from any source, for example:
 public class ExampleObjectJsonTests {
     private BasicJsonTester json = new BasicJsonTester(getClass());
     @Test
     public void testWriteJson() throws IOException {
         assertThat(json.from("example.json")).extractingJsonPathStringValue("@.name")
                                .isEqualTo("Spring");
     }
 }
 
 See AbstractJsonMarshalTester for more details.- Since:
- 1.4.0
- Author:
- Phillip Webb, Andy Wilkinson
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCreate a new uninitializedBasicJsonTesterinstance.BasicJsonTester(Class<?> resourceLoadClass) Create a newBasicJsonTesterinstance that will load resources as UTF-8.BasicJsonTester(Class<?> resourceLoadClass, Charset charset) Create a newBasicJsonTesterinstance.
- 
Method SummaryModifier and TypeMethodDescriptionfrom(byte[] source) Create JSON content from the specified JSON bytes.Create JSON content from the specified JSON file.from(InputStream source) Create JSON content from the specified JSON input stream.from(CharSequence source) Create JSON content from the specified String source.Create JSON content from the specified resource path.Create JSON content from the specified JSON resource.protected final voidinitialize(Class<?> resourceLoadClass) Initialize the marshal tester for use, configuring it to load JSON resources as UTF-8.protected final voidinitialize(Class<?> resourceLoadClass, Charset charset) Initialize the marshal tester for use.
- 
Constructor Details- 
BasicJsonTesterprotected BasicJsonTester()Create a new uninitializedBasicJsonTesterinstance.
- 
BasicJsonTesterCreate a newBasicJsonTesterinstance that will load resources as UTF-8.- Parameters:
- resourceLoadClass- the source class used to load resources
 
- 
BasicJsonTesterCreate a newBasicJsonTesterinstance.- Parameters:
- resourceLoadClass- the source class used to load resources
- charset- the charset used to load resources
- Since:
- 1.4.1
 
 
- 
- 
Method Details- 
initializeInitialize the marshal tester for use, configuring it to load JSON resources as UTF-8.- Parameters:
- resourceLoadClass- the source class used when loading relative classpath resources
 
- 
initializeInitialize the marshal tester for use.- Parameters:
- resourceLoadClass- the source class used when loading relative classpath resources
- charset- the charset used when loading relative classpath resources
- Since:
- 1.4.1
 
- 
fromCreate JSON content from the specified String source. The source can contain the JSON itself or, if it ends with.json, the name of a resource to be loaded usingresourceLoadClass.- Parameters:
- source- the JSON content or a- .jsonresource name
- Returns:
- the JSON content
 
- 
fromCreate JSON content from the specified resource path.- Parameters:
- path- the path of the resource to load
- resourceLoadClass- the source class used to load the resource
- Returns:
- the JSON content
 
- 
fromCreate JSON content from the specified JSON bytes.- Parameters:
- source- the bytes of JSON
- Returns:
- the JSON content
 
- 
fromCreate JSON content from the specified JSON file.- Parameters:
- source- the file containing JSON
- Returns:
- the JSON content
 
- 
fromCreate JSON content from the specified JSON input stream.- Parameters:
- source- the input stream containing JSON
- Returns:
- the JSON content
 
- 
fromCreate JSON content from the specified JSON resource.- Parameters:
- source- the resource containing JSON
- Returns:
- the JSON content
 
 
-