-
I have repository with field type |
Beta Was this translation helpful? Give feedback.
Answered by
frank06
Dec 14, 2022
Replies: 2 comments 3 replies
-
as a temporary solution, I made all non-primitive objects to be converted into strings. But this is not very good in my opinion, especially for serialization. BaseAdapter: @override
Future<DeserializedData<T>> deserialize(Object? data) {
final value = data as Map<String, dynamic>;
handle(Map<String, dynamic> v) {
for(final i in v.entries) {
final value = i.value;
if(value != null && i.value is Map) {
v[i.key] = jsonEncode(i.value);
}
}
}
if(value['data'] is Iterable) {
final list = (value['data'] as List<dynamic>).cast<Map<String, dynamic>>();
for(final item in list) {
handle(item);
}
return super.deserialize(value['data']);
}
else {
handle(value);
}
return super.deserialize(data);
}
@override
Future<Map<String, dynamic>> serialize(model, {bool withRelationships = true}) async {
final result = await super.serialize(model, withRelationships: withRelationships);
for(final item in result.entries) {
final value = item.value;
if(value != null && value is String && value.startsWith('{') && value.endsWith('}')) {
result[item.key] = jsonDecode(value);
}
}
return result;
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
On what runtime? Web? |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Enhed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On what runtime? Web?