Automapper map Array to Object with example

Automapper Map Array to object map

Today in this article, we will see how to perform Automapper map Array to Object of a different type.

Updated November 2026: sections on collapsing an array into one object and on null, existing-collection and missing-map behaviour, plus an FAQ and a security upgrade note.

Today in this article, we will cover below aspects,

To keep it simple, we shall use very simple examples and later look into all possible combinations of the map array to object or map object to an array or even map array to array mapping examples.

We already learned in our article on Getting started with Automapper in ASP.NET Core.

What is AutoMapper

AutoMapper is an object mapper that helps you transform one object of one type into an output object of a different type. This type of transformation is often needed when you work on business logic.

Automapper helps to centralize your repeated boring mapping logic, address the separation of concerns, provide better control on mapping making your code clean and easy to maintain.

We shall be using the below classes where we have source type as “CheckingAccountSource” and destination as “CheckingAccountDestination”.

I have used the class naming convention as simple for understanding purposes.

Below is our sample source JSON file,

{
  "ID": "Bank of ABCD",
  "Branches": [
    {
      "Address": [
        {
          "StreetName": "address1",
          "ZipCode": "Zip",
          "ST": "USA"
        },
        {
          "StreetName": "address1",
          "Zip": "Zip",
          "ST": "USA"
        }
      ]
    }
  ]
}

Below is the expected destination JSON output after mapping file,

{
  "Bank": "Bank of ABCD",
  "BranchInfo": [
    {
        "Location": 
          {
            "Street": "address1",
            "Zip": "Zip",
            "State": "USA"
          }  
    }
  ]
}

Let’s define the Source and destination classes as below. here below our aim is to map the array from source to the object.

So nee here is to map only the first element from the array of objects to the destination object.

Automapper map Array to Object with example

In the above example, We have a very simple one-to-one mapping which can be achieved easily by creating the below Mapping profile.

DI IMapper into the module

Dependency Injection of the IMapper interface is explained here already with more details,

Automapper map Array to Object – Configuring Profile Instances

Here you need to create a class that inherits from the class Profile then please add your configuration of mapping into the Constructor.

Profiles are one the best way of organizing all your mapping configurations in one place.

Below is Automapper profile for the array of object mapping.

   public class CheckingAccountProfile : Profile
    {
        public CheckingAccountProfile()
        {
            CreateMap<CheckingAccountSource, CheckingAccountDestination>()
              .ForMember(dest => dest.Bank, o => o.MapFrom(src => src.ID))
              .ForMember(dest => dest.BranchInfo, o => o.MapFrom(src => src.Branches));

            CreateMap<Branches, BranchInfo>()
             .ForMember(dest => dest.Location, o => o.MapFrom(src => src.Address[0]));

            CreateMap<Address, Location>()
            .ForMember(dest => dest.Street, o => o.MapFrom(src => src.ST))
            .ForMember(dest => dest.State, o => o.MapFrom(src => src.StreetName))
            .ForMember(dest => dest.Zip, o => o.MapFrom(src => src.ZipCode));

        }

..

..

}

Here is a simplified example to perform Mapping objects to an array of objects.

        [HttpPost]
        public IActionResult UpdateEmployee([FromBody] CheckingAccountSource soureObject)
        {
            var destObject = _mapper.Map<Destination>(soureObject);

            _logger.LogInformation("Mapping successful");

            return Ok(destObject);
        }

Automapper Array to Object

Below are a few additional scenarios, which are covered in the link below,

Scenario 1

Map an array of objects into a single object using an auto mapper. For more details, please visit the below article –

Scenario 2

Map an array of objects from the source to an array of objects using an auto mapper.

Useful References :

Do you have any comments or ideas or any better suggestions to share?

Please sound off your comments below.

Happy Coding !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published (2026) best practices and guidelines for software design and development.



How do you collapse a string[] or object[] into one object with AutoMapper?

AutoMapper has no default map from an array to a single object, because it can’t guess how the elements should combine. You have to say how, and you have two options: a global type converter or a per-member mapping.

Global option: a type converter

Declare CreateMap<string[], Target>().ConvertUsing(...) and you’ve defined the rule for that whole type pair. ConvertUsing accepts a Func, an ITypeConverter instance, or an ITypeConverter type. Use the type form when the converter needs its own class or dependencies.

Note: A type converter is like a translator you hire for one language pair. Once hired, every document in that pair goes through them, whether you remember or not.

The rule applies everywhere that pair is mapped, including nested properties. Choose it when the rule is identical on every call.

Per-member option: MapFrom or a value resolver

Use ForMember with MapFrom or a value resolver on the parent map. It affects one destination property only. Choose it when the array is a property of a larger object and the rule belongs to that map alone.

Which one should you pick?

The trade-off is reach against clarity. This table compares the two.

ApproachScopeBest for
ConvertUsingEvery map of that type pairOne rule used across the codebase
ForMember + MapFromOne property on one mapA rule specific to that parent map

A converter is reusable, but it silently changes every map of that pair. MapFrom stays local, and a reader sees the rule right next to the member it fills. Default to MapFrom and move to a converter only when you catch yourself repeating the same expression.

The same fix for “Missing type map configuration”

The same idea resolves the error Missing type map configuration or unsupported mapping. It appears when AutoMapper has no map between two types, such as a string and a custom class. AutoMapper also has no built-in conversion from string to types like int, DateTime or Type. It throws at map time, and again when you validate the configuration, until you add a CreateMap with ConvertUsing for that pair.

When AutoMapper isn’t worth it

For a one-off conversion of a few elements, a plain LINQ Select or a hand-written constructor is shorter and easier to debug. You can step through it, and there’s no configuration to keep in sync. Reach for AutoMapper when the same mapping repeats across the codebase and a single definition saves you from copying it.

Frequently asked questions

Do I need to call CreateMap for the array type as well as the element type?

No. Only the element type needs a map. CreateMap<Source, Destination>() is enough to map Source[] to Destination[], List<Destination>, IList<Destination>, ICollection<Destination> or IEnumerable<Destination>. Then call mapper.Map<Destination[]>(sources) or mapper.Map<List<Destination>>(sources).

How do I map an array to a List<T> or IEnumerable<T> with AutoMapper?

Use the same element map and change the destination type argument, for example mapper.Map<Source[], List<Destination>>(sources). No extra configuration is needed for the collection type. Swap List<Destination> for IEnumerable<Destination> and the same profile still works.

Why do I get “Missing type map configuration or unsupported mapping” when mapping an array?

AutoMapper has no map for the element pair, or you’re mapping a type it can’t convert on its own, such as a string to a custom class. Add a CreateMap for the element types, or add a CreateMap with ConvertUsing for the conversion. Calling AssertConfigurationIsValid in a unit test catches this early, before the mapping runs in production.

What happens when the source array is null?

A null source collection property maps to an empty destination collection, not null. So you can usually iterate the destination without a null check. When you map into an existing collection, AutoMapper clears it first, so existing items are lost. If you need to merge instead, look at AutoMapper.Collection.

Leave a Reply

Your email address will not be published. Required fields are marked *