Skip to content

NullReferenceException when mapping from multiple sources when one source is null #414

Open
@jkuek

Description

@jkuek

I have 3 source items to map to a destination. There is a possibility the third item will be null.

I create a config as follows:

            var config = TypeAdapterConfig<(a, b, c), Output>.NewConfig()
                .Map(dest => dest, src => src.Item1)
                .Map(dest => dest, src => src.Item2)
                .Map(dest => dest.Application, src => src.Item3 == null ? (Application) null : new Application()
                {
                    Id = src.Item3.Id,
                    Name = src.Item3.Name
                })

My expectation was that a null value for Item3 should be handled and a null value returned for the Application property of the output.

When I run the mapping:
var result = (x, y, z)Adapt<Output>(config.Config);
when z is null, then a NullReferenceException is thrown.

Is this a bug?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions