Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Created July 16, 2022 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtmuller5/6456181b915526be31509a0fa512cba7 to your computer and use it in GitHub Desktop.
Save jtmuller5/6456181b915526be31509a0fa512cba7 to your computer and use it in GitHub Desktop.
Json converter for lists of integers
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