SmartKeyEncodingStrategy

public enum SmartKeyEncodingStrategy : Sendable

Undocumented

  • Use the keys specified by each type. This is the default strategy.

    Declaration

    Swift

    case useDefaultKeys
  • Convert from “camelCaseKeys” to “snake_case_keys” before writing a key to JSON payload.

    Capital characters are determined by testing membership in Unicode General Categories Lu and Lt. The conversion to lower case uses Locale.system, also known as the ICU “root” locale. This means the result is consistent regardless of the current user’s locale and language preferences.

    Converting from camel case to snake case:

    1. Splits words at the boundary of lower-case to upper-case
    2. Inserts _ between words
    3. Lowercases the entire string
    4. Preserves starting and ending _.

    For example, oneTwoThree becomes one_two_three. _oneTwoThree_ becomes _one_two_three_.

    Note

    Using a key encoding strategy has a nominal performance cost, as each string key has to be converted.

    Declaration

    Swift

    case toSnakeCase
  • Convert the first letter of the key to lower case before attempting to match a key with the one specified by each type. For example, OneTwoThree becomes oneTwoThree.

    Note

    This strategy should be used with caution, especially if the key’s first letter is intended to be uppercase for distinguishing purposes. It also incurs a nominal performance cost, as the first character of each key needs to be inspected and possibly modified.

    Declaration

    Swift

    case firstLetterLower
  • Convert the first letter of the key to upper case before attempting to match a key with the one specified by each type. For example, oneTwoThree becomes OneTwoThree.

    Note

    This strategy should be used when the keys are expected to start with a lowercase letter and need to be converted to start with an uppercase letter. It incurs a nominal performance cost, as the first character of each key needs to be inspected and possibly modified.

    Declaration

    Swift

    case firstLetterUpper