You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@liamappelbe, Since Java null references are represented as null/JObject?, should the JNI conversion API mirror package:objective_c with separate toDartObject(JObject) and toNullableDartObject(JObject?) functions, or should toDartObject itself accept JObject? and handle null?
This also affects deep collection conversion, since JList, JSet, JMap, and JArray can contain nullable JObject? elements/keys/values. Should those converters preserve null recursively as Dart null?
Since Java null references are represented as null/JObject?, should the JNI conversion API mirror package:objective_c with separate toDartObject(JObject) and toNullableDartObject(JObject?) functions, or should toDartObject itself accept JObject? and handle null?
Yeah, copy package:objective_c's approach here.
This also affects deep collection conversion, since JList, JSet, JMap, and JArray can contain nullable JObject? elements/keys/values. Should those converters preserve null recursively as Dart null?
I think this bit will diverge a bit from ObjC land. Java's null safety is generally very weak. Whereas in ObjC, collections cannot contain null (they have a special NSNull object instead).
ObjC's generics are also a bit weaker than Java's, and much weaker than Dart's. Our Dart ObjC wrappers don't support generics at all.
I see 2 options:
Return JList<JObject?>, and let the user use .cast() to convert to whatever type they want.
Make the conversion utils generic, so the user can do something like toDartObject<List<int>> and we do the casting internally.
Obviously option 2 is better, I'm just not 100% sure it's possible using Dart's generics. See what you can do.
@liamappelbe, I experimented with making the Java -> Dart collection converters generic. A helper like JList<JObject?>.toDartList() works for one-level conversions such as List<int?>, including nulls.
For nested types like List<List>, Dart preserves T = List but I couldn't find a way to generically extract the inner type argument, so the recursive conversion produces List<Object?> and the cast fails.
I tried allowing an optional element converter:
toDartList({T Function(JObject?)? convertElement, ...})
which allows nested typed conversions by supplying the nested conversion explicitly. Is this a valid approach?
Ok, then maybe a util that returns List<Object?> that the user can manually .cast() is the best approach (I can see I typo'd that in my previous comment as List<JObject?>, but yeah, JObject won't work for primitives).
Activity
deep4nsh commentedon Feb 27, 2026
Hi 👋 I'd like to work on this issue.
From my understanding, this involves adding utility functions
for deep conversion in the JNI layer.
Before I start, could you please confirm:
Thanks!
liamappelbe commentedon Mar 2, 2026
This is a follow up to #3093, which hasn't landed yet. You'll need to wait for that.
Siya-05 commentedon Sep 11, 2026
hey @liamappelbe, Can I work on this?
liamappelbe commentedon Sep 11, 2026
@Siya-05 sure. The APIs should match
package:objective_c's conversion APIs as closely as possible.Siya-05 commentedon Sep 13, 2026
@liamappelbe, Since Java null references are represented as null/JObject?, should the JNI conversion API mirror package:objective_c with separate toDartObject(JObject) and toNullableDartObject(JObject?) functions, or should toDartObject itself accept JObject? and handle null?
This also affects deep collection conversion, since JList, JSet, JMap, and JArray can contain nullable JObject? elements/keys/values. Should those converters preserve null recursively as Dart null?
liamappelbe commentedon Sep 14, 2026
Yeah, copy
package:objective_c's approach here.I think this bit will diverge a bit from ObjC land. Java's null safety is generally very weak. Whereas in ObjC, collections cannot contain
null(they have a specialNSNullobject instead).ObjC's generics are also a bit weaker than Java's, and much weaker than Dart's. Our Dart ObjC wrappers don't support generics at all.
I see 2 options:
JList<JObject?>, and let the user use.cast()to convert to whatever type they want.toDartObject<List<int>>and we do the casting internally.Obviously option 2 is better, I'm just not 100% sure it's possible using Dart's generics. See what you can do.
Siya-05 commentedon Sep 14, 2026
@liamappelbe, I experimented with making the Java -> Dart collection converters generic. A helper like JList<JObject?>.toDartList() works for one-level conversions such as List<int?>, including nulls.
For nested types like List<List>, Dart preserves T = List but I couldn't find a way to generically extract the inner type argument, so the recursive conversion produces List<Object?> and the cast fails.
I tried allowing an optional element converter:
toDartList({T Function(JObject?)? convertElement, ...})
which allows nested typed conversions by supplying the nested conversion explicitly. Is this a valid approach?
liamappelbe commentedon Sep 14, 2026
Ok, then maybe a util that returns
List<Object?>that the user can manually.cast()is the best approach (I can see I typo'd that in my previous comment asList<JObject?>, but yeah,JObjectwon't work for primitives).