Skip to content

Support flattening of dynamic properties in Map<String, Any> with proper serialization and introspection #1089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
betulince opened this issue May 6, 2025 · 3 comments
Labels

Comments

@betulince
Copy link

betulince commented May 6, 2025

Issue description

Expected Behavior

I'm trying to wrap a Map<String, Any> inside a Parameters class to be used as part of a JobRequest. The goal is to deserialize dynamic JSON objects with arbitrary fields into this map and serialize them back as a flattened structure like:

{
  "parameters": {
    "foo": "bar",
    "baz": 42
  }
}

I expected to be able to achieve this by using a simple wrapper around a map, similar to Jackson's @JsonAnyGetter/@JsonAnySetter, or via Micronaut annotations such as @Serdeable, @SerdeImport, or @SerdeConfig.

Actual Behavior

Despite attempting the above approaches, I encountered either of the following:

  • Runtime error: No serializable introspection present for type Parameters
  • Or the structure is serialized with an unwanted extra layer (parameterValues) like:
{
  "parameters": {
    "parameterValues": {
      "foo": "bar",
      "baz": 42
    }
  }
}

Additionally, using alternatives such as JsonNode or JsonObject instead of Map<String, Any> also resulted in bean introspection errors.

Steps To Reproduce

You can reproduce this with the sample app and failing test provided here:
sample application

Clone the repository and run the test to observe the error.

Environment Information

  • Micronaut Version: 3.10.1
  • Kotlin version: 1.6.21

Additional Notes

This issue is blocking for use cases where DTOs need to accept flexible, dynamic request bodies without predefining the schema, and respond with the same shape.

If possible, a mechanism similar to Jackson’s @JsonAnyGetter would be ideal for clean flattening.

@dstepanov
Copy link
Contributor

This should be the annotation processor dependency:
implementation("io.micronaut.serde:micronaut-serde-processor")

@dstepanov
Copy link
Contributor

Or KAPT / KSP

@betulince
Copy link
Author

I tried adding implementation("io.micronaut.serde:micronaut-serde-jackson") and annotationProcessor("io.micronaut.serde:micronaut-serde-processor"), and also tried using kapt as an annotation processor, but I'm still seeing the same serialization error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants