Skip to content
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

Add functionality similar to Jackson's @JsonUnwrapped #326

Open
ferrazoli opened this issue Jan 13, 2025 · 3 comments
Open

Add functionality similar to Jackson's @JsonUnwrapped #326

ferrazoli opened this issue Jan 13, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@ferrazoli
Copy link

See https://fasterxml.github.io/jackson-annotations/javadoc/2.8/com/fasterxml/jackson/annotation/JsonUnwrapped.html

@SentryMan SentryMan added the enhancement New feature or request label Jan 13, 2025
@SentryMan
Copy link
Collaborator

I mean I don't mind adding it, but like why would someone want to do this?

@ferrazoli
Copy link
Author

There's a lot of potential use cases. For instance, I have a lot of typed IDs in my project, e.g.:

record UserId (
  UUID id
) {}

If I have a User record such as:

record User (
  UserId id,
  String email,
  String name,
  ...
) {}

I don't want my serialized User to be:

{
  "id": {
    "id": "some uuid"
  },
  "email": "[email protected]",
  "name": "Some Name",
  ...
}

So it's helpful to be able to easily "flatten" certain objects.

Of course I could also provide a custom serializer, or even create an extra record for the API layer alone, but that adds a lot of boilerplate code.

@SentryMan
Copy link
Collaborator

There's a lot of potential use cases. For instance, I have a lot of typed IDs in my project, e.g.:

record UserId (
UUID id
) {}

You can actually make this work now with @Value

record UserId (
 @Json.Value  UUID id
) {}

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

No branches or pull requests

2 participants