micronaut-projects / micronaut-serialization

Build Time Serialization APIs for Micronaut
Apache License 2.0
26 stars 19 forks source link

Question: possible to use micronaut-serialization library alone (without the micronaut framework)? #876

Closed dxxvi closed 1 month ago

dxxvi commented 3 months ago

Issue description

This is the only micronaut-related library I use:

    <dependency>
      <groupId>io.micronaut.serde</groupId>
      <artifactId>micronaut-serde-jackson</artifactId>
      <version>2.10.2</version>
    </dependency>

Could somebody write me some code to serialize an instance of this class?

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.serde.annotation.Serdeable;

@Serdeable
public class GameScore {
  @JsonProperty(value = "game_id", required = true)
  private final String gameId; // playerId is in the message key

  @JsonProperty(value = "score", required = true)
  private final int score;

  @JsonCreator
  public GameScore(String gameId, int score) {
    this.gameId = gameId;
    this.score = score;
  }

  public String getGameId() {
    return gameId;
  }

  public int getScore() {
    return score;
  }
}
graemerocher commented 3 months ago

maven or Gradle?