Skip to content

Commit

Permalink
review comments pt1
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseymoore committed May 23, 2024
1 parent 3724156 commit 8ed823e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
8 changes: 4 additions & 4 deletions examples/dart/test/serialization_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:test/test.dart';
import 'package:realm_dart/realm.dart';
import 'utils.dart';

part 'serialization_test.realm.dart';

Expand All @@ -24,10 +25,10 @@ main() {
});

// :snippet-start: serialize
// Serialize to ejson by passing the object as a paramter to the method or ...
// Pass the object as a parameter to the method
EJsonValue serializeByParam = toEJson(spider);

// ... by calling the method directly on the object
// Call the method directly on the object
EJsonValue serializeWithCall = spider.toEJson();
// :snippet-end:

Expand All @@ -37,7 +38,6 @@ main() {
print(serializeByParam);

EJsonValue different = spider.toEJson();
print('new');
print(different);

final birthDate = DateTime.utc(2024, 4, 10);
Expand All @@ -55,7 +55,7 @@ main() {

test('deserialize', () {
// :snippet-start: deserialize
// Deserialize from ejson
// Pass the serialized object to the method
Pet deserializeFromEjson = fromEJson(serializeByParam);
// :snippet-end:

Expand Down
28 changes: 23 additions & 5 deletions source/sdk/flutter/realm-database/serialization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The following data types can be serialized and deserialized:
- Null
- Undefined

The SDK does not yet support the following types: Code, CodeWScope, DBPointer,
The SDK does not currently support the following types: Code, CodeWScope, DBPointer,
DBRef, Regular Expression, and Timestamp.

For more information and examples on the serialization for each of these types,
Expand All @@ -63,7 +63,8 @@ object model will be used in the following examples:
Serialization
-------------

For objects in a Realm, you can serialize to EJSON using the ``toEjson()`` method.
For objects in a Realm, you can serialize to EJSON using the
:flutter-sdk:`toEjson() <realm/toEJson.html>` method in the following two ways:

.. literalinclude:: /examples/generated/flutter/serialization_test.snippet.serialize.dart
:language: dart
Expand All @@ -79,12 +80,29 @@ The outputted EJSON looks like the following:
price: null
}

.. io-code-block::
:copyable: true

.. input:: /examples/generated/node/mongodb.snippet.filter-documents.js
:language: js

.. output::
:language: json
:visible: true

{
type: Jumping Spider,
numberOfLegs: {$numberInt: 8},
birthDate: {$date: {$numberLong: 1712707200000}},
price: null
}

Deserialization
---------------

Deserialize from EJSON using the ``fromEJSON()`` method. The method takes EJSON
for a specified object type as input and outputs a deserialized instance of the
specified object type.
Deserialize from EJSON using the :flutter-sdk:`fromEjson() <realm/fromEJson.html>`
method. The method takes EJSON for a specified object type as input and outputs
a deserialized instance of the specified object type.

.. literalinclude:: /examples/generated/flutter/serialization_test.snippet.deserialize.dart
:language: dart

0 comments on commit 8ed823e

Please sign in to comment.