unit-test-json-serialization

Solid

Provides patterns for unit testing JSON serialization/deserialization with Jackson and `@JsonTest`. Validates JSON mapping, custom serializers, date formats, and polymorphic types. Use when testing JSON serialization, validating custom serializers, or writing JSON unit tests in Spring Boot applications.

Testing & QA 261 stars 29 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 89/100

Stars 20%
81
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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>...

Details

Author
giuseppe-trisciuoglio
Repository
giuseppe-trisciuoglio/developer-kit
Created
7 months ago
Last Updated
1 weeks ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

Testing & QA Solid

unit-test-mapper-converter

Provides patterns for unit testing mappers, converters, and bean mappings. Validates entity-to-DTO and model transformation logic in isolation. Generates executable mapping tests with MapStruct and custom converter test coverage. Use when writing mapping tests, converter tests, entity mapping tests, or ensuring correct data transformation between DTOs and domain objects.

261 Updated 1 weeks ago
giuseppe-trisciuoglio
Testing & QA Solid

unit-test-controller-layer

Provides patterns for unit testing REST controllers using MockMvc and @WebMvcTest. Generates controller tests that validates request/response mapping, validation, exception handling, and HTTP status codes. Use when testing web layer endpoints in isolation for API endpoint testing, Spring MVC tests, mock HTTP requests, or controller layer unit tests.

261 Updated 1 weeks ago
giuseppe-trisciuoglio
Testing & QA Solid

unit-test-bean-validation

Provides patterns for unit testing Jakarta Bean Validation (JSR-380), including @Valid, @NotNull, @Min, @Max, @Email constraints with Hibernate Validator. Generates custom validator tests, constraint violation assertions, validation groups, and parameterized validation tests. Validates data integrity logic without Spring context. Use when writing validation tests, bean validation tests, or testing custom constraint validators.

261 Updated 1 weeks ago
giuseppe-trisciuoglio
Testing & QA Solid

unit-test-exception-handler

Provides patterns for unit testing `@ExceptionHandler` and `@ControllerAdvice` in Spring Boot applications. Validates error response formatting, mocks exceptions, verifies HTTP status codes, tests field-level validation errors, and asserts custom error payloads. Use when writing Spring exception handler tests, REST API error tests, or mocking controller advice.

261 Updated 1 weeks ago
giuseppe-trisciuoglio
AI & Automation Listed

jackson

Jackson serialization/deserialization conventions for Spring Boot 3.x. Auto-loads when editing `**/*Dto.java`, `**/*Request.java`, `**/*Response.java`, `**/ObjectMapper*.java`, `**/JsonConfig*.java`. Covers ObjectMapper config, polymorphic deserialization (subtype whitelist), JavaTimeModule, mixins, mass-assignment prevention.

1 Updated yesterday
taipt1504