Skip to content

Commit 5e95ba5

Browse files
Support external type JsonToNative #148
1 parent 9836d7c commit 5e95ba5

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

objectbox/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
sure to update to `io.objectbox:objectbox-android-objectbrowser:4.3.0` in `android/app/build.gradle`.
77
* Update ObjectBox database for Flutter iOS/macOS apps to 4.3.0.
88
For existing projects, run `pod repo update` and `pod update ObjectBox` in the `ios` or `macos` directories.
9+
* External property types (via [MongoDB connector](https://sync.objectbox.io/mongodb-sync-connector)):
10+
add `jsonToNative` to support sub (embedded/nested) documents/arrays in MongoDB.
911

1012
## 4.2.0 (2025-04-15)
1113

objectbox/lib/src/annotations.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,19 @@ enum ExternalPropertyType {
593593
/// Representing type: String
594594
javaScript,
595595

596+
/// A JSON string that is converted to a native representation in the external
597+
/// system.
598+
///
599+
/// For example, a JSON object on the ObjectBox side (string) would be
600+
/// converted to an embedded document in MongoDB.
601+
///
602+
/// It depends on the external system what kind of JSON structures is
603+
/// supported. For MongoDB, this is very flexible and allows (nested) objects,
604+
/// arrays, primitives, etc.
605+
///
606+
/// Representing type: String
607+
jsonToNative,
608+
596609
/// A vector (array) of Int128 values.
597610
int128Vector,
598611

objectbox/lib/src/modelinfo/enums.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ int externalTypeToOBXExternalType(ExternalPropertyType type) {
258258
return OBXExternalPropertyType.Bson;
259259
case ExternalPropertyType.javaScript:
260260
return OBXExternalPropertyType.JavaScript;
261+
case ExternalPropertyType.jsonToNative:
262+
return OBXExternalPropertyType.JsonToNative;
261263
case ExternalPropertyType.int128Vector:
262264
return OBXExternalPropertyType.Int128Vector;
263265
case ExternalPropertyType.uuidVector:

objectbox_test/test/entity.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ class EntityWithExternalType {
490490
@ExternalName(name: 'my-mongo-rel')
491491
final mongoIdEntities = ToMany<EntityWithExternalType>();
492492

493+
@ExternalType(type: ExternalPropertyType.jsonToNative)
494+
String? externalJsonToNative;
495+
493496
EntityWithExternalType(this.mongoId, this.mongoUuid);
494497
}
495498

objectbox_test/test/objectbox-model.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@
727727
},
728728
{
729729
"id": "16:5931645853908059165",
730-
"lastPropertyId": "3:7670802129899081197",
730+
"lastPropertyId": "4:6250975810854368520",
731731
"name": "EntityWithExternalType",
732732
"externalName": "my-mongo-entity",
733733
"properties": [
@@ -749,6 +749,12 @@
749749
"type": 27,
750750
"externalType": 102,
751751
"externalName": "my-mongo-uuid"
752+
},
753+
{
754+
"id": "4:6250975810854368520",
755+
"name": "externalJsonToNative",
756+
"type": 9,
757+
"externalType": 112
752758
}
753759
],
754760
"relations": [

0 commit comments

Comments
 (0)