Extension Methods for adding JSON APIs to a Realm Instance
PM> Install-Package RealmJson.Extensions
Ref: https://www.nuget.org/packages/RealmJson.Extensions
###Post issues on GitHub
Post on StackOverflow with the tags: [XAMARIN]
[REALM]
[JSON]
https://sushihangover.github.io/Realm.Json.Extensions/
-
A Realm Instance:
- .CreateAllFromJson<T>(string)
- .CreateAllFromJson<T>(Stream)
- .CreateAllFromJsonViaAutoMapper<T>(Stream)
- .CreateObjectFromJson<T>(string)
- .CreateObjectFromJson<T>(Stream)
- .CreateOrUpdateObjectFromJson<T>(string)
- .CreateOrUpdateObjectFromJson<T>(Stream)
- .CreateOrUpdateObjectFromJson<T>(Stream)
-
A RealmObject Instance:
- .NonManagedCopy<T>()
-
A RealmResult Instance (IQueryable):
- .NonManagedCopy
https://github.com/sushihangover/Realm.Json.Extensions
var syncedObject = realmObject.NonManagedCopy<ARealmClass>();
Re: https://stackoverflow.com/a/46629763/4984832
using (var theRealm = Realm.GetInstance(RealmDBTempPath()))
{
var realmObject = theRealm.CreateObjectFromJson<StateUnique>(jsonString);
}
using (var stream = new MemoryStream(byteArray))
using (var theRealm = Realm.GetInstance(RealmDBTempPath()))
{
var testObject = theRealm.CreateObjectFromJson<StateUnique>(stream);
}
using (var theRealm = Realm.GetInstance(RealmDBTempPath()))
using (var assetStream = Application.Context.Assets.Open("States.json"))
{
theRealm.CreateAllFromJson<State>(assetStream);
}
using (var theRealm = Realm.GetInstance(RealmDBTempPath()))
using (var fileStream = new FileStream("./Data/States.json", FileMode.Open, FileAccess.Read))
{
theRealm.CreateAllFromJson<State>(fileStream);
}
Note: Consult the Unit Tests for more usage details
AutoMapper
does not support PCL Profile 259
(2)) and thus adding this Nuget package will fail if applied to a default Xamarin.Form
project.
You can change your Xamarin.From project to Profile 111
, then retarget the Xamarin.Forms
package, and you will be able to add the Nuget package.
See the Xamarin.Forms
-based (Nuget.Test
) project in the code repo as an example.
Note: Once Xamarin has full support for .NET Standard
and AutoMapper releases v5.2 (3), this mess should go away.
(2) AutoMapper/AutoMapper#1531
(3) AutoMapper/AutoMapper#1532
##Build Documention:
API Reference documention is built via the great
xbuild /p:SolutionDir=./ /target:Clean /p:Configuration=Release RealmJson.Extensions/RealmJson.Extensions.csproj
xbuild /p:SolutionDir=./ /target:Build /p:Configuration=Release RealmJson.Extensions/RealmJson.Extensions.csproj
adb shell am instrument -w RealmJson.Test.Droid/app.tests.TestInstrumentation
Ref: Automate Android Nunit Test
Ref: Issue 32005
xbuild RealmJson.Test.iOS/RealmJson.Test.iOS.csproj /p:SolutionDir=~/
xcrun simctl list
open -a Simulator --args -CurrentDeviceUDID 360D3BC6-4A6D-4B7E-A899-5C7651EC2107
xcrun simctl install booted ./RealmJson.Test.iOS/bin/iPhoneSimulator/Debug/RealmJson.Test.iOS.app
xcrun simctl launch booted com.sushihangover.realmjson-test-ios
cat ~/Library/Logs/CoreSimulator/360D3BC6-4A6D-4B7E-A899-5C7651EC2107/system.log
There is a #if PERF
within Tests.Shared.Perf.Streaming.cs
that contains multple tests to evaluate streaming performance and memory overhead.
These test methods try to evaluate:
Realm.Manage
vs.AutoMapper
performance/effeciency- Upper limits of the number of
RealmObject
s can be used in a RealmTransaction
on a mobile device.
See Perf.md for details.
Consult LICENSE