Skip to content

Commit

Permalink
fix table format
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseymoore committed Jul 9, 2024
1 parent b832398 commit bbdc7d4
Showing 1 changed file with 23 additions and 44 deletions.
67 changes: 23 additions & 44 deletions source/sdk/flutter/realm-database/serialization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Serialization - Flutter SDK
:class: singlecol

The Atlas Device SDK for Flutter supports serialization and deserialization of
:manual:`Extended JSON (ESJON) </reference/mongodb-extended-json>` to and from static Realm objects.
:manual:`Extended JSON (EJSON) </reference/mongodb-extended-json>` to and from static Realm objects.
Serialization allows for easier integration with MongoDB APIs.

Supported Data Types for Serialization
Expand All @@ -28,67 +28,42 @@ The Flutter SDK supports serialization of the following data types:

.. list-table::
:header-rows: 1
:widths: 30 30 40
:widths: 30 70

* - Realm Data Type
- BSON Data Type
- Example

* - Integer (min: -2147483648, max: +2147483647)
- Int32
- ``int number32 = 900`` serializes to ``number32: {"$numberInt": 900}``

* - Integer (min: -9223372036854775808, max: +9223372036854775807)
- Int64
- ``int number64 = 922393736854775807`` serializes to ``number64: {$numberLong: 922393736854775807}``

* - Boolean
- Boolean
- ``bool isElectric = false`` serializes to ``isElectric: false``

* - Double
- Double
- ``double milesDriven = 126.0`` serializes to ``milesDriven: {$numberDouble: 126.0}``

* - String
- String
- ``String licensePlate = "690ZXWYZ"`` serializes to ``licensePlate: 690ZXWYZ``
* - Realm Type
- Serializes To

* - DateTime
- Date
- ``DateTime birthDate = DateTime.utc(2024, 4, 10)`` serializes to ``birthDate: {$date: {$numberLong: 1712707200000}}``
``DateTime birthDate = DateTime.utc(2024, 4, 10)`` serializes to ``birthDate: {$date: {$numberLong: 1712707200000}}``

* - RealmList
- Array
- ``List<String> listOfStrings = [food, water]`` serializes to ``listOfStrings: [food, water]``
``List<String> listOfStrings = [food, water]`` serializes to ``listOfStrings: [food, water]``

* - RealmMap
- Array
- ``Map<String, int> mapOfMixedAnyValues = {'first': 123 , 'second': 567}`` serializes to ``mapOfValues: {first: {$numberInt: 123}, second: {$numberInt: 567}}``
``Map<String, int> mapOfMixedAnyValues = {'first': 123 , 'second': 567}`` serializes to ``mapOfValues: {first: {$numberInt: 123}, second: {$numberInt: 567}}``

* - RealmSet
- Array
- ``Set<int> setOfInts = {0, 1, 2, 3}`` serializes to ``setOfInts: [{$numberInt: 0}, {$numberInt: 1}, {$numberInt: 2}, {$numberInt: 3}]``
``Set<int> setOfInts = {0, 1, 2, 3}`` serializes to ``setOfInts: [{$numberInt: 0}, {$numberInt: 1}, {$numberInt: 2}, {$numberInt: 3}]``

* - ObjectId
- ObjectId
- ``ObjectId id = ObjectId()`` serializes to ``{id: {$oid: 666a6fd54978af08e54a8d52}``
``ObjectId id = ObjectId()`` serializes to ``{id: {$oid: 666a6fd54978af08e54a8d52}``

* - UUID
- Binary
- ``Uuid myId = Uuid.v4()`` serializes to ``myId: {$binary: {base64: 6TvsMWxDRWa1jSC6gxiM3A==, subType: 04}}``
``Uuid myId = Uuid.v4()`` serializes to ``myId: {$binary: {base64: 6TvsMWxDRWa1jSC6gxiM3A==, subType: 04}}``

* - Uint8List
- Binary
- ``Uint8List aBinaryProperty = Uint8List.fromList([1, 2])`` serializes to ``aBinaryProperty: {$binary: {base64: AQI=, subType: 00}}``
``Uint8List aBinaryProperty = Uint8List.fromList([1, 2])`` serializes to ``aBinaryProperty: {$binary: {base64: AQI=, subType: 00}}``

* - Embedded Object
- Document
- ``Address address = Address("500 Dean Street", "Brooklyn", "NY", "USA")`` serializes to ``address: {street: 500 Dean Street, city: Brooklyn, state: NY, country: USA}``

* - Null
- Null
- ``int? apples`` serializes to ``apples: null``
``Address address = Address("500 Dean Street", "Brooklyn", "NY", "USA")`` serializes to ``address: {street: 500 Dean Street, city: Brooklyn, state: NY, country: USA}``

For more information and examples on the serialization for each of these types,
see :manual:`BSON Data Types and Associated Representations </reference/mongodb-extended-json/#bson-data-types-and-associated-representations>`.
Expand All @@ -99,17 +74,21 @@ CodeWScope, DBPointer, DBRef, Regular Expression, and Timestamp.
Serialize Realm Objects
-----------------------

Full-document encoding enables you to serialize and deserialize user-defined
classes. You can create your object model as you normally would. The RealmObject class
model created by your ``part`` declaration provides the necessary encoder
and decoder methods for serialization and deserialization. The following ``Pet``
object model will be used in the following examples:
The SDK's full-document encoder enables you to serialize and deserialize user-defined
classes.

To use the encoder, create your object model as you normally would using
the ``@RealmModel()`` annotation. The ``RealmObject`` class
model created by your ``part`` declaration provides the necessary methods
for serialization and deserialization.

The following ``Pet`` object model will be used in the examples on this page:

.. literalinclude:: /examples/generated/flutter/pet.snippet.serialize-object-model.dart
:language: dart

Serialize to EJSON
------------------
~~~~~~~~~~~~~~~~~~

For objects based on ``RealmObject`` classes, you can serialize to EJSON using the
:flutter-sdk:`toEjson() <realm/toEJson.html>` method in the following two ways:
Expand All @@ -130,7 +109,7 @@ For objects based on ``RealmObject`` classes, you can serialize to EJSON using t
}

Deserialize from EJSON
----------------------
~~~~~~~~~~~~~~~~~~~~~~

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
Expand Down

0 comments on commit bbdc7d4

Please sign in to comment.