Created
July 16, 2022 21:55
-
-
Save jtmuller5/6456181b915526be31509a0fa512cba7 to your computer and use it in GitHub Desktop.
Json converter for lists of integers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:json_annotation/json_annotation.dart'; | |
class IntListConverter implements JsonConverter<List<int>?, String> { | |
const IntListConverter(); | |
@override | |
List<int>? fromJson(String? json) => List<int>.from(jsonDecode(json ?? '[]').map((e) => e.toInt())); | |
@override | |
String toJson(List<int>? object) => jsonEncode(object); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment