unit-test-json-serialization_skill

This skill provides patterns for unit testing JSON serialization and deserialization with Jackson and JsonTest to validate mappings and formats.
  • Python

99

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill giuseppe-trisciuoglio/developer-kit --skill unit-test-json-serialization

  • SKILL.md12.2 KB

Overview

This skill provides practical patterns for unit testing JSON serialization and deserialization using Spring's @JsonTest and Jackson. It focuses on fast, focused tests for POJOs, custom serializers/deserializers, date/time formatting, polymorphic types, nested structures, and null handling without loading a full Spring context. Examples and pitfalls are included to make tests reliable and maintainable.

How this skill works

Annotate tests with @JsonTest to auto-configure JacksonTester for type-safe JSON assertions. Use JacksonTester to write objects to JSON and parse JSON back to objects, combine JsonPath extractions for targeted assertions, and verify behaviors like @JsonProperty mappings, @JsonIgnore exclusions, custom JsonSerializer output, and temporal formatting. Tests run quickly because only JSON-related beans are loaded.

When to use it

  • Validating DTO mapping for REST requests and responses
  • Verifying custom JsonSerializer/JsonDeserializer implementations
  • Ensuring date/time fields serialize to and parse from expected formats
  • Testing nested objects, collections, and polymorphic types
  • Checking null handling and presence/absence of JSON properties

Best practices

  • Annotate with @JsonTest and inject JacksonTester<T> for focused tests
  • Always test both serialization and deserialization for critical fields
  • Use JsonPath assertions to check specific paths instead of string matching
  • Cover nulls, empty collections, and missing fields explicitly
  • Test custom serializers and @JsonProperty mappings with dedicated examples

Example use cases

  • Unit test a UserDto to ensure field names and types map correctly to JSON
  • Verify a custom money serializer emits a '$99.99' string for BigDecimal
  • Deserialize an array of UserDto and assert order and values
  • Confirm LocalDateTime fields serialize as ISO-8601 and parse back
  • Validate polymorphic PaymentMethod deserialization using type metadata

FAQ

@JsonTest loads only JSON-related configuration and Jackson support, making tests faster and isolating JSON mapping behavior. Use @SpringBootTest only when you need the full application context.

How do I test custom serializers?

Annotate the target field with @JsonSerialize(using = YourSerializer.class), then use JacksonTester.write(...) and assert the JSON path contains the expected serialized string.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
unit-test-json-serialization skill by giuseppe-trisciuoglio/developer-kit | VeilStrat