Specifies a predefined property name conversion for serialization and deserialization.
This interface serves two purposes:
- It defines the globally predefined naming strategy constants (e.g.
IDENTITY,LOWER_CASE_WITH_DASHES) that can be passed toJsonbConfig.withPropertyNamingStrategy(String). - It can be implemented directly to provide a custom naming strategy, which can be passed to
JsonbConfig.withPropertyNamingStrategy(PropertyNamingStrategy).
All naming stategies apply to the identity property name which is determined by one of the following program elements:
- field name
- JavaBean property name
- record component name
- record virtual attribute name
A naming strategy applies globally to all serialized and deserialized types. The stategy transforms the identity property name into a JSON property name.
Interaction with other naming customizations
A JsonbProperty annotation on a field,
record component, accessor method, virtual attribute, or constructor/factory-method parameter takes
precedence over this strategy for that individual property. The strategy is applied to properties
only when no such annotation is present.
- Since:
- JSON Binding 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDuring serialization, theIDENTITYstrategy is used; the property name is written to JSON unchanged.static final StringThe identity property name is used unchanged as the JSON property name.static final StringThe identity property name is transformed to lower case with dashes.static final StringThe identity property name is transformed to lower case with underscores.static final StringThe first character of the identity property name is capitalized; the remainder is unchanged.static final StringThe first character of the property name is capitalized and camel-case word boundaries are replaced with spaces. -
Method Summary
Modifier and TypeMethodDescriptiontranslateName(String propertyName) Translates an identity property name into its JSON property name representation according to this strategy.
-
Field Details
-
IDENTITY
The identity property name is used unchanged as the JSON property name.
This is the default naming stategy.
- See Also:
-
LOWER_CASE_WITH_DASHES
The identity property name is transformed to lower case with dashes.
Dashes are inserted at camel-case boundaries in the identity property name
For example,
myPropertyNamebecomesmy-property-name.- See Also:
-
LOWER_CASE_WITH_UNDERSCORES
The identity property name is transformed to lower case with underscores.
Underscores are inserted at camel-case boundaries in the identity property name.
For example,
myPropertyNamebecomesmy_property_name.- See Also:
-
UPPER_CAMEL_CASE
The first character of the identity property name is capitalized; the remainder is unchanged.
For example,
myPropertyNamebecomesMyPropertyName.- See Also:
-
UPPER_CAMEL_CASE_WITH_SPACES
The first character of the property name is capitalized and camel-case word boundaries are replaced with spaces.
For example,
myPropertyNamebecomesMy Property Name.- See Also:
-
CASE_INSENSITIVE
During serialization, the
IDENTITYstrategy is used; the property name is written to JSON unchanged.During deserialization, JSON property name matching is case-insensitive.
For example, a JSON property named
PropertyNAMEwill be mapped to the identity property namepropertyName.- See Also:
-
-
Method Details
-
translateName
Translates an identity property name into its JSON property name representation according to this strategy.
The returned value is used as the JSON property name during serialization and as the expected JSON property name during deserialization, unless overridden by a
JsonbPropertyannotation.- Parameters:
propertyName- identity property name to translate.- Returns:
- the translated JSON property name.
-