1

Is there a GSON equivalent annotation for Jackson's @get:JsonValue?

I have the below enum and I need the GSON annotation as well.

enum class TransactionType(@get:JsonValue val code: Int) { ... }
ikos23
  • 4,879
  • 10
  • 41
  • 60
C96
  • 477
  • 8
  • 33
  • I'm familiar with Jackson's `@JsonValue` and not `@get:JsonValue` (so a link to that would be appreciated) so this may not be helpful but are you looking for `@SerializedName`? https://www.javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/annotations/SerializedName.html – Paul Oct 07 '20 at 14:14
  • The answer is probably there but I cant say its easily extractable – C96 Oct 07 '20 at 14:29
  • `@get:` just means that the annotation will be attached to the getter, not the field. Nothing stops you from doing that in Java – Clashsoft Oct 07 '20 at 14:42

1 Answers1

1

It was:

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.")
}

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

cela
  • 2,352
  • 3
  • 21
  • 43
C96
  • 477
  • 8
  • 33