JsonValue class

Makes one value stand for the whole object in JSON: an enum constant's JSON form, or a small value class written as a plain string or number.

On a field or getter of an enum, its value is each constant's JSON form instead of the constant's name (also as a map key; an int one is matched by value, never as an index). On a property (field or getter) or a method without parameters of an @Introspected class, the object is written as that value and read back through a constructor with one parameter (Jackson's delegating creator) or its fromJson. One per class; a second one fails the build.

// The API says "in_stock"; Dart says inStock.
enum Stock {
  inStock('in_stock'),
  soldOut('sold_out');

  const Stock(this.json);
  @JsonValue()
  final String json;
}
// Stock.inStock  ↔  "in_stock"

// A typed id that is a plain string in JSON.
@Introspected()
class Isbn {
  const Isbn(this.value);
  @JsonValue()
  final String value;
}
// Isbn('978-0')  ↔  "978-0"

Spring (Java):

enum Stock {
  IN_STOCK("in_stock");
  @JsonValue final String json;
}
record Isbn(@JsonValue String value) {}

Constructors

JsonValue()
Marks the field, getter or method whose value stands for the object.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited