built_value is a beloved package and one of the most popular source generators among Flutter developers. However, working with it isn’t always straightforward, and not every error message is easy to decipher.

Deserializing failed due to '_InternalLinkedHashMap<String, dynamic>' is not subtype of type 'Iterable' is another one of those frustratingly vague error messages that once had me banging my head against the wall for an entire day!

In reality, this error stems from a serializer issue. Serializers are something we need to configure to tell built_value how we want to serialize and deserialize our data. This particular problem usually occurs when you’ve specified the wrong serializer in your fromJson(String jsonString) method. Fortunately, the fix is simple: switch the serializer in the fromJson(String jsonString) method to the custom one you’ve created (typically the one that includes the Standard Json Plugin for JSON handling—in other words, one where you’ve added addPlugin(StandardJsonPlugin())).

So if your code currently looks like this:

static MyModel fromJson(String jsonString) {
  return serializers.deserializeWith(
    MyModel.serializer,
    json.decode(jsonString));
}

Change it to:

static MyModel fromJson(String jsonString) {
  return mySerializers.deserializeWith(
    MyModel.serializer,
    json.decode(jsonString));
}

In other words, simply change serializers to mySerializers.

Thanks for reading

📚 Hope you enjoy reading!