
Unit Test Json Serialization
Add Spring Boot @JsonTest unit patterns so Jackson serialization, custom serializers, and date formats are verified before release.
Overview
Unit Test JSON Serialization is an agent skill for the Ship phase that provides @JsonTest and JacksonTester patterns to unit-test JSON serialization and deserialization in Spring Boot applications.
Install
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill unit-test-json-serializationWhat is this skill?
- Spring @JsonTest setup with autowired JacksonTester for type-safe JSON assertions
- Covers @JsonProperty, @JsonIgnore, custom serializers, and nested object mapping
- Tests LocalDateTime, Date formatting, nulls, missing fields, and polymorphic types
- Five-step instruction flow: annotate, autowire, serialize, deserialize, round-trip
- Explicit when-to-use list for DTO verification and custom serializer validation
- Instructions define a 5-step @JsonTest workflow from annotation through round-trip validation
Adoption & trust: 1.2k installs on skills.sh; 271 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You ship Spring DTOs with Jackson annotations but lack fast tests proving JSON shape, dates, and custom serializers won't break clients.
Who is it for?
Indie backend devs on Spring Boot who want agent-guided Jackson unit tests before merging API changes.
Skip if: Non-JVM stacks or teams that only need OpenAPI contract tests with no Jackson code paths.
When should I use this skill?
Testing JSON serialization, validating custom serializers, or writing JSON unit tests in Spring Boot applications.
What do I get? / Deliverables
You get repeatable @JsonTest classes with serialization, deserialization, and round-trip assertions guarding API JSON contracts.
- @JsonTest test classes with serialization and deserialization assertions
- Round-trip coverage for DTO JSON contracts
- Documented patterns for polymorphic and date/time JSON edge cases
Recommended Skills
Journey fit
JSON mapping bugs often surface at deploy boundaries; this skill belongs on Ship testing as the gate for DTO contracts and serializer regressions. Testing subphase because the skill is exclusively about @JsonTest assertions, round-trips, and Jackson edge cases—not feature implementation.
How it compares
Focused Jackson @JsonTest recipes—not a full Testcontainers or E2E API harness.
Common Questions / FAQ
Who is unit test json serialization for?
Solo builders and small teams maintaining Spring Boot services who need reliable Jackson JSON unit tests on DTOs and custom serializers.
When should I use unit test json serialization?
During Ship testing when changing REST payloads, adding @JsonProperty mappings, or validating polymorphic or date JSON formats before release.
Is unit test json serialization safe to install?
It guides test authoring with Read/Write/Bash tools—review the Security Audits panel on this Prism page and scope Bash usage to your test module.
SKILL.md
READMESKILL.md - Unit Test Json Serialization
# Unit Testing JSON Serialization with `@JsonTest` ## Overview Provides patterns for unit testing JSON serialization and deserialization using Spring's `@JsonTest` and Jackson. Covers POJO mapping, custom serializers, field name mappings, nested objects, date/time formatting, and polymorphic types. ## When to Use - Testing JSON serialization/deserialization of DTOs - Verifying custom Jackson serializers/deserializers - Validating `@JsonProperty`, `@JsonIgnore`, and field name mappings - Testing date/time format handling (LocalDateTime, Date) - Testing null handling and missing fields - Testing polymorphic type deserialization ## Instructions 1. **Annotate test class with `@JsonTest`** → Enables JacksonTester auto-configuration 2. **Autowire JacksonTester for target type** → Provides type-safe JSON assertions 3. **Test serialization** → Call `json.write(object)` and assert JSON paths with `extractingJsonPath*` 4. **Test deserialization** → Call `json.parse(json)` or `json.parseObject(json)` and assert object state 5. **Validate round-trip** → Serialize, then deserialize, verify same data (if object is properly comparable) 6. **Test edge cases** → Null values, missing fields, empty collections, invalid JSON 7. **Add validation checkpoints**: After each assertion, verify the test fails meaningfully with wrong data ## Examples ### Maven Setup ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-json</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> ``` ### Gradle Setup ```kotlin dependencies { implementation("org.springframework.boot:spring-boot-starter-json") testImplementation("org.springframework.boot:spring-boot-starter-test") } ``` ### Basic Serialization and Deserialization ```java @JsonTest class UserDtoJsonTest { @Autowired private JacksonTester<UserDto> json; @Test void shouldSerializeUserToJson() throws Exception { UserDto user = new UserDto(1L, "Alice", "alice@example.com", 25); JsonContent<UserDto> result = json.write(user); result .extractingJsonPathNumberValue("$.id").isEqualTo(1) .extractingJsonPathStringValue("$.name").isEqualTo("Alice") .extractingJsonPathStringValue("$.email").isEqualTo("alice@example.com") .extractingJsonPathNumberValue("$.age").isEqualTo(25); } @Test void shouldDeserializeJsonToUser() throws Exception { String json_content = "{\"id\":1,\"name\":\"Alice\",\"email\":\"alice@example.com\",\"age\":25}"; UserDto user = json.parse(json_content).getObject(); assertThat(user.getId()).isEqualTo(1L); assertThat(user.getName()).isEqualTo("Alice"); assertThat(user.getEmail()).isEqualTo("alice@example.com"); assertThat(user.getAge()).isEqualTo(25); } @Test void shouldHandleNullFields() throws Exception { String json_content = "{\"id\":1,\"name\":null,\"email\":\"alice@example.com\"}"; UserDto user = json.parse(json_content).getObject(); assertThat(user.getName()).isNull(); } } ``` ### Custom JSON Properties ```java public class Order { @JsonProperty("order_id") private Long id; @JsonProperty("total_amount") private BigDecimal amount; @JsonIgnore private String internalNote; } @JsonTest class OrderJsonTest { @Autowired private JacksonTester<Order> json; @Test void shouldMapJsonPropertyNames() throws Exception { String json_content = "{\"order_id\":123,\"total_amount\":99.99}"; Order order = jso