Split generated JsonXExtensions into smaller modular files#88
Split generated JsonXExtensions into smaller modular files#88DrakslerT wants to merge 2 commits into
Conversation
|
@copilot generate a summary of the changes |
There was a problem hiding this comment.
Pull request overview
Refactors JsonX extensions code generation to split the previously monolithic generated JsonXExtensions output into multiple smaller generated files while keeping a shared JVM facade name.
Changes:
- Generate one extensions file per model holder (resource-specific extension functions).
- Generate separate files for the shared serializer module/
formatproperty and shared “core” extensions. - Add new
JsonApiConstants.FileNamesentries to support the new generated file names.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| processor/src/main/java/com/infinum/jsonapix/processor/specs/jsonxextensions/JsonXSerializerModuleSpecBuilder.kt | Adds a dedicated spec builder for generating the serializer module + format property file. |
| processor/src/main/java/com/infinum/jsonapix/processor/specs/jsonxextensions/JsonXModelExtensionsSpecBuilder.kt | Adds a per-model extensions FileSpec builder (resource-specific extension functions). |
| processor/src/main/java/com/infinum/jsonapix/processor/specs/jsonxextensions/JsonXCoreExtensionsSpecBuilder.kt | Adds a spec builder for shared/core JsonX extension functions (deserialize, relationship helpers, error decoding, retrofit helper). |
| processor/src/main/java/com/infinum/jsonapix/processor/specs/generators/JsonXExtensionsSpecGenerator.kt | Updates generation flow to emit multiple files instead of one aggregated file. |
| core/src/main/java/com/infinum/jsonapix/core/common/JsonApiConstants.kt | Adds new constants for the newly generated file names. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fileSpec.addAnnotation( | ||
| AnnotationSpec.builder(JvmName::class) | ||
| .addMember("%S", JsonApiConstants.FileNames.JSON_X_EXTENSIONS) | ||
| .useSiteTarget(AnnotationSpec.UseSiteTarget.FILE).build(), | ||
| ) | ||
| fileSpec.addAnnotation( | ||
| AnnotationSpec.builder(JvmMultifileClass::class) | ||
| .useSiteTarget(AnnotationSpec.UseSiteTarget.FILE).build(), | ||
| ) |
There was a problem hiding this comment.
This is added as before, the JsonXExtensions file used the JVM name:
![]()
Not sure if its even needed though @thisAAY 🤔
|
@thisAAY the current structure is like this: Do we want to change it in any way? or spread it |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|




Summary
The annotation processor previously generated all extension functions and serialization infrastructure into a single monolithic
JsonXExtensions.ktfile. This refactors the generator to emit three focused files while preserving the same public API surface via@file:JvmMultifileClass.Related issue: None
Changes
Type
Additional information
Description
All three generated files carry
@file:JvmName("JsonXExtensions")+@file:JvmMultifileClass, so the API surface is unchanged from a consumer perspective.Generated file breakdown:
{Model}Extensions.kt(one per annotated class) — model-specific extension functions:Original.toResourceObject(meta, links),Model.toResourceObject(),Item.toResourceObject()Model.toJsonApiX(),List.toJsonApiXList()Model.toJsonApiXString(...),List.toJsonApiXString(...)JsonXSerializerModule.kt— serialization infrastructure shared across all models:jsonApiXSerializerModule(polymorphic registrations for all models, custom links/errors/meta)format(Jsoninstance)JsonXCoreExtensions.kt— shared stateless utilities:toManyRelationshipModel()/toOneRelationshipModel()decodeJsonApiError<T>()asJsonXHttpException<T>()(emitted only when the retrofit module is on the classpath)decodeJsonApiXString()/decodeJsonApiXListString()Processor changes:
JsonXExtensionsSpecGeneratornow collects each holder's data into aClassInfomap and delegates to the three new builders.JsonXCoreExtensionsSpecBuilder,JsonXModelExtensionsSpecBuilder,JsonXSerializerModuleSpecBuilder— new builder objects replacing the old monolithicJsonXExtensionsSpecBuilder.JsonApiConstants.FileNames— addedJSON_X_CORE_EXTENSIONSandJSON_X_SERIALIZER_MODULEconstants.Checklist
Additional notes
Compile-time output grows from 1 file to
N + 2files (where N = number of annotated models), but incremental compilation benefit improves since only the affected model's file needs regeneration on change.