RealmJson class
JSON <-> RealmObject serialization helpers with automatic nested object support.
Serialization Strategy (in order of preference):
- Generated toEJson() - Best option, automatically handles all nested RealmObjects
- Schema introspection - Auto-detects properties when toEJson() unavailable
- Explicit property lists - Manual specification for edge cases
Deserialization Strategy:
- fromEJsonMap<T>() - Recommended, uses generated fromEJson() for automatic nested object handling
- fromJsonWith<T>() - Manual deserialization with explicit property lists
Round-Trip Serialization:
// Initialize schemas
ChatUser.schema;
ChatRoom.schema;
// Serialize
final json = RealmJson.toJsonWith(chatRoom, null);
// Deserialize (round-trip)
final restored = RealmJson.fromEJsonMap<ChatRoom>(json);
Supported types:
- Primitives: String, int, double, bool
- DateTime (UTC converted to/from ISO-8601)
- ObjectId, Uuid (string representation)
- Decimal128 (string representation)
- Uint8List (base64 encoding)
- RealmValue (mixed type with type metadata)
- Collections: RealmList, RealmSet, RealmMap
- Relationships: Embedded objects, to-one, to-many (fully recursive)
- Backlinks are automatically skipped during serialization
Constructors
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
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromEJsonMap<
T extends dynamic> (Map< String, dynamic> json, {T create()?, List<String> ? propertyNames, Map<String, dynamic Function(Map< ? embeddedCreators}) → TString, dynamic> )> - Deserialize a RealmObject from JSON using generated fromEJson() method.
-
fromJsonWith<
T extends dynamic> (Map< String, dynamic> json, T create(), List<String> propertyNames, {Map<String, dynamic Function(Map< ? embeddedCreators}) → TString, dynamic> )> - Hydrate a RealmObject from JSON using explicit property names.
-
toJsonWith(
dynamic obj, List< String> ? propertyNames, {Map<String, List< ? embeddedProperties}) → Map<String> >String, dynamic> - Serialize a RealmObject into JSON using the provided property names.