CamelCaseNamingStrategy class

Leaves field names unchanged (camelCase).

This is the default Dart naming strategy where JSON field names are kept the same as Dart field names. Use this strategy when your JSON API already uses camelCase or when you want to preserve the exact field names without transformation.

Identity Transformation:

  • camelCase to camelCase: No changes applied
  • camelCase from camelCase: No changes applied

Examples:

final strategy = CamelCaseNamingStrategy();

// Both directions preserve the original name
strategy.toJsonName('userName');        // 'userName'
strategy.toJsonName('HTTPRequest');     // 'HTTPRequest'
strategy.toJsonName('userId');          // 'userId'
strategy.toJsonName('XMLParser');       // 'XMLParser'
strategy.toJsonName('createdAt');       // 'createdAt'

strategy.toDartName('userName');        // 'userName'
strategy.toDartName('HTTPRequest');     // 'HTTPRequest'
strategy.toDartName('userId');          // 'userId'
strategy.toDartName('XMLParser');       // 'XMLParser'
strategy.toDartName('createdAt');       // 'createdAt'

Usage with JSON Serialization:

@Serializable(namingStrategy: CamelCaseNamingStrategy())
class User {
  final String firstName;
  final String lastName;
  final DateTime createdAt;
  final bool isActive;

  User(this.firstName, this.lastName, this.createdAt, this.isActive);
}

// Serializes to: 
// {
//   "firstName": "John",
//   "lastName": "Doe", 
//   "createdAt": "2023-01-01T10:00:00Z",
//   "isActive": true
// }

When to Use:

  • When working with JavaScript/TypeScript APIs that use camelCase
  • When the JSON schema matches your Dart class structure exactly
  • When you want maximum performance (no string transformations)
  • As a base class for composite naming strategies

Performance:

This strategy has minimal overhead since it performs no string transformations, making it the most performant option.

See also:

Implemented types

Constructors

CamelCaseNamingStrategy()
Leaves field names unchanged (camelCase).
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
toDartName(String name) String
Converts a JSON field name back into a Dart-compatible identifier.
override
toJsonName(String name) String
Converts a Dart field name into a JSON-compatible name.
override
toString() String
A string representation of this object.
inherited

Operators

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