Skip to content

Split generated JsonXExtensions into smaller modular files#88

Open
DrakslerT wants to merge 2 commits into
masterfrom
refactor/JsonXExtensions
Open

Split generated JsonXExtensions into smaller modular files#88
DrakslerT wants to merge 2 commits into
masterfrom
refactor/JsonXExtensions

Conversation

@DrakslerT

@DrakslerT DrakslerT commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Summary

The annotation processor previously generated all extension functions and serialization infrastructure into a single monolithic JsonXExtensions.kt file. This refactors the generator to emit three focused files while preserving the same public API surface via @file:JvmMultifileClass.

Related issue: None

Changes

Type

  • Feature: This pull request introduces a new feature.
  • Bug fix: This pull request fixes a bug.
  • Refactor: This pull request refactors existing code.
  • Documentation: This pull request updates documentation.
  • Other: This pull request makes other changes.

Additional information

  • This pull request introduces a breaking change.

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 (Json instance)
  • 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:

  • JsonXExtensionsSpecGenerator now collects each holder's data into a ClassInfo map and delegates to the three new builders.
  • JsonXCoreExtensionsSpecBuilder, JsonXModelExtensionsSpecBuilder, JsonXSerializerModuleSpecBuilder — new builder objects replacing the old monolithic JsonXExtensionsSpecBuilder.
  • JsonApiConstants.FileNames — added JSON_X_CORE_EXTENSIONS and JSON_X_SERIALIZER_MODULE constants.

Checklist

  • I have performed a self-review of my own code.
  • I have tested my changes, including edge cases.
  • I have added necessary tests for the changes introduced (if applicable).
  • I have updated the documentation to reflect my changes (if applicable).

Additional notes

Compile-time output grows from 1 file to N + 2 files (where N = number of annotated models), but incremental compilation benefit improves since only the affected model's file needs regeneration on change.

@DrakslerT

Copy link
Copy Markdown
Contributor Author

@copilot generate a summary of the changes

Copilot AI changed the title Split up generated JsonXExtensions into smaller modular files Split generated JsonXExtensions into smaller modular files Apr 8, 2026
@infinum infinum deleted a comment from Copilot AI Apr 8, 2026
@DrakslerT DrakslerT requested a review from thisAAY April 8, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/format property and shared “core” extensions.
  • Add new JsonApiConstants.FileNames entries 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.

Comment on lines +41 to +49
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(),
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is added as before, the JsonXExtensions file used the JVM name:
Image

Now all the files have:
Image

Not sure if its even needed though @thisAAY 🤔

@DrakslerT

Copy link
Copy Markdown
Contributor Author

@thisAAY the current structure is like this:
Screenshot 2026-04-08 at 10 31 11

Do we want to change it in any way? or spread it

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Apr 8, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
14.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@DrakslerT DrakslerT self-assigned this Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants