toJson method
Implementation
Object? toJson(Object? Function(T? value) callback) {
final rootValue = callback(value);
final entries = values.entries.map((e) {
final mapped = callback(e.value);
if (mapped == null) return null;
return MapEntry(e.key, mapped);
}).whereType<MapEntry<String, Object>>();
final map = Map.fromEntries(entries);
if (rootValue != null) map['en'] = rootValue;
if (map.length <= 1) return rootValue;
return map;
}