feat: JSON handling with JSON.jl v1.0 and StructTypes #90
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Summary
This PR refactors the core serialization and deserialization logic in
OpenAPI.jlto leverage the modern features ofJSON.jlv1.0 and theStructTypes.jlecosystem. This change simplifies the codebase, improves maintainability, and enhances performance by removing custom object-mapping machinery in favor of a standardized, declarative approach.Motivation
The existing implementation relies on
JSON.jlv0.21 and uses a customJSONWrapperstruct to handle the omission ofnothingfields during serialization. While functional, this approach adds boilerplate and predates the modern object-mapping standards in the Julia ecosystem.This upgrade provides several key benefits:
JSONWrapperwith a single, declarative line (StructTypes.omitempties) and removes a significant amount of boilerplate code fromsrc/json.jl.JSON.readfor direct struct deserialization, which avoids allocating an intermediateDictand can lead to reduced memory usage and faster parsing times.StructTypes.jl) for object mapping, reducing the maintenance burden onOpenAPI.jlitself.Key Changes
Dependency Update:
StructTypes.jlas a new dependency.[compat]entry forJSON.jlto1.Serialization (
src/json.jl):JSONWrapperstruct and its associated methods have been completely removed.StructTypes.StructTypeandStructTypes.omitemptiesare now defined forAPIModel, providing a declarative way to handle struct serialization and omitnothingfields.Deserialization (
src/json.jl,src/client.jl,src/server.jl):StructTypes.constructhook is used to delegate object construction to our existingfrom_jsonlogic. This preserves all custom handling for date/time types, discriminated unions (oneOf/anyOf), and other special cases.responsefunction insrc/client.jlnow usesJSON.read(body, T)for direct, one-step deserialization.src/server.jlhas been updated to useJSON.read.src/server.jlthat has a significant performance benefit. The original code would parse the JSON, serialize it back to bytes, and then the calling code would parse it again. This new version directly extracts the raw bytes of the JSON chunk, avoiding the unnecessary intermediate stepsImpact on Generated Code
A major advantage of this approach is its minimal impact on the code generated by the OpenAPI Generator. Because the core logic is centralized in the
OpenAPI.jlruntime viaStructTypeshooks, the individualmodel_*.jlfiles andapi_*.jlfiles do not require any changes. The existing generated code will work seamlessly with this updated implementation.Testing
Full Integration Suite: All existing E2E tests (
petstore,forms,allany, etc.) pass successfully. This confirms that the entire client-server request-response lifecycle functions correctly with the new JSON handling.Contributor Checklist
src/json.jl.src/client.jlandsrc/server.jl.StructTypes.jltoProject.tomland updatedJSON.jlcompat entry.test/runtests.jlpass successfully.