micronaut-projects / micronaut-projects/micronaut-serialization

@JsonValue ignored by micronaut-serde

Open
#780 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: improvement
Dominant language
Java
Stars
36
Forks
29
Avg merge
1d 21h
Merged PRs (30d)
29

Description

Expected Behavior

JSON body after serialization:

{"courier":"ups-mi"}
Actual Behaviour

JSON body after serialization:

{"courier":"UPS_MAIL_INNOVATION"}
Steps To Reproduce
  1. Use com.fasterxml.jackson.annotation.JsonValue annotation in enum.
    For example:
public enum Courier {

    UPS("ups"),
    USPS("usps"),
    UPS_MAIL_INNOVATION("ups-mi"),
    ASENDIA("asendia-usa"),
    DHL("dhl-gm");

    private final String code;

    Courier(String code) {
        this.code = code;
    }

    @JsonValue
    public String getCode() {
        return code;
    }
}
  1. After serialization I have next JSON:
{"courier":"UPS_MAIL_INNOVATION"}
  1. But I should have:
{"courier":"ups-mi"}

You can find example with serde here.
Example with jackson (works correct) here.

Environment Information

Mac OS Sonoma 14.3.1
JDK 21

Example Application

https://github.com/alexey-plotnikoff/micronaut-serde

Version

4.3.4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked micronaut-serde example application and reproduce enum serialization using com.fasterxml.jackson.annotation.JsonValue. Compare its output with the linked micronaut-jackson example, then trace the enum serialization entry point. Done means the Courier value serializes as its code, such as "ups-mi", rather than the enum constant name.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.