spring-projects / spring-projects/spring-boot

Support method injection of JSON testers

Open
#48,528 4 comments 0 reactions 1 assignee View on GitHub

@snicoll is already working on this.

Since Mar 25, 2026.

status: pending-design-work type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

Something like this:

@JdbcTest
@AutoConfigureJsonTesters
class SampleTests {

    @Test
    void sampleTest(@Autowired BasicJsonTester jsonTester) {
        assertThat(jsonTester.from("{}")).hasJsonPath("$");
    }

}

Fails with:

Uninitialized BasicJsonTester
java.lang.IllegalStateException: Uninitialized BasicJsonTester
	at org.springframework.util.Assert.state(Assert.java:80)
	at org.springframework.boot.test.json.BasicJsonTester.verify(BasicJsonTester.java:166)
	at org.springframework.boot.test.json.BasicJsonTester.from(BasicJsonTester.java:110)
	at com.example.SampleTests.sampleTest(SampleTests.java:17)

Looking at JsonTestersAutoConfiguration and JsonMarshalTestersBeanPostProcessor, only fields are considered for tester initialization:

https://github.com/spring-projects/spring-boot/blob/10e2f34eccb1152c9a8259f64d2d5c0456288892/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java#L74-L78

This prevents consistent code style in codebases where method injection is preferred.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.