PropertyNamingStrategy enum
A rule that turns Dart property names (publishedAt) into JSON names
(published_at), applied to every property of a class or of the whole
mapper.
Use it when the JSON you exchange follows another convention than Dart's
lowerCamelCase, such as a snake_case API, instead of writing
@JsonProperty on every field. Set it for all classes with
ObjectMapper(namingStrategy: ...) (in Spring Boot, the property
spring.json.property-naming-strategy), or for one class with
@JsonNaming. A name given by @JsonProperty is used as it is. The
translation follows Jackson's PropertyNamingStrategies, acronyms
included.
// Talk to a snake_case API.
PropertyNamingStrategy.snakeCase.translate('publishedAt'); // published_at
PropertyNamingStrategy.snakeCase.translate('myURLValue'); // my_urlvalue
PropertyNamingStrategy.kebabCase.translate('URLValue'); // url-value
ObjectMapper(namingStrategy: PropertyNamingStrategy.snakeCase);
Spring (Java):
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
Values
- lowerCamelCase → const PropertyNamingStrategy
-
The Dart name unchanged:
publishedAt. The default. - upperCamelCase → const PropertyNamingStrategy
-
The first letter upper-cased:
PublishedAt. - snakeCase → const PropertyNamingStrategy
-
Lower case, words joined by
_:published_at. - upperSnakeCase → const PropertyNamingStrategy
-
Upper case, words joined by
_:PUBLISHED_AT. - kebabCase → const PropertyNamingStrategy
-
Lower case, words joined by
-:published-at. - lowerCase → const PropertyNamingStrategy
-
Lower case, no separator:
publishedat. - lowerDotCase → const PropertyNamingStrategy
-
Lower case, words joined by
.:published.at.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- index → int
-
A numeric identifier for the enumerated value.
no setterinherited
- name → String
-
Available on Enum, provided by the EnumName extension
The name of the enum value.no setter - 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
-
translate(
String name) → String -
Returns the JSON name for the Dart property
name.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
parse(
String value) → PropertyNamingStrategy -
Returns the strategy a configuration value names, such as
SNAKE_CASE,snake_case,snakeCaseorkebab-case(case,-,_,.and spaces are ignored).
Constants
-
values
→ const List<
PropertyNamingStrategy> - A constant List of the values in this enum, in order of their declaration.