JsonPropertyOrder class

Puts chosen properties of a class first when it is written, for JSON that people read or that a fixed format expects.

Put it on the class. The listed names (JSON or Dart names) come first, in that order; the others follow in the mapper's order, sorted alphabetically unless ObjectMapper.sortPropertiesAlphabetically is off. JsonPropertyOrder.alphabetic sorts the unlisted ones alphabetically even when the mapper does not (Jackson's alphabetic = true). Reading does not depend on the order.

// The id and title lead, whatever else the book has.
@Introspected()
@JsonPropertyOrder(['id', 'title'])
class Book { ... } // {"id":..., "title":..., then the rest}

@Introspected()
@JsonPropertyOrder.alphabetic()
class Tag { ... } // sorted, whatever the mapper says

Spring (Java):

@JsonPropertyOrder({"id", "title"})
class Book { ... }

@JsonPropertyOrder(alphabetic = true)
class Tag { ... }

Constructors

JsonPropertyOrder(List<String> value)
Writes the properties value first, in that order.
const
JsonPropertyOrder.alphabetic({List<String> value = const []})
Writes the properties value first (none by default), then the others sorted alphabetically.
const

Properties

alphabetic → bool
Whether the properties that are not listed are sorted alphabetically regardless of the mapper's setting.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → List<String>
The property names written first, in this order.
final

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