【问题标题】:Jackson annotation @get:JsonValue, GSON equivalent [duplicate]Jackson 注释 @get:JsonValue,GSON 等效项 [重复]
【发布时间】:2021-01-22 11:57:16
【问题描述】:

Jackson 的@get:JsonValue 是否有 GSON 等效注释?

我有以下枚举,我也需要 GSON 注释。

enum class TransactionType(@get:JsonValue val code: Int) { ... }

【问题讨论】:

  • 我熟悉 Jackson 的 @JsonValue 而不是 @get:JsonValue(因此请提供指向该链接的链接),所以这可能没有帮助,但您是否在寻找 @SerializedNamejavadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/…
  • 答案可能就在那里,但我不能说它很容易提取
  • @get: 只是意味着注释将附加到getter,而不是字段。没有什么能阻止你在 Java 中这样做

标签: java json spring jackson gson


【解决方案1】:

原来是:

enum class Type(@get:JsonValue val code: Int, val description: String) {
    @SerializedName("0") NEGATIVE(2, "negative amount "),
    @SerializedName("1") CREDIT(3,"Credit."),
    @SerializedName("2") WAGERS(6,"wager"),
    @SerializedName("3") ZERO(8, "zero.")
}

参考: https://javadoc.io/doc/com.google.code.gson/gson/2.8.1/com/google/gson/annotations/package-summary.html

【讨论】:

    猜你喜欢
    • 2012-05-14
    • 2017-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-28
    • 2014-11-10
    • 1970-01-01
    相关资源
    最近更新 更多