.NET Core API Complex Map not getting third layer json using swagger

Cris 21 Reputation points
2022-05-26T14:53:51.027+00:00

Hi I have a Complex Map three layer but I am not getting the third level json

public class DetailResponse
{
List<Comments> CommentsList { get; set; }
}
public class Comments
{
public string Content { get; set; }
public FileInfo AttachInfo;
}

public class FileInfo
{
public string ID { get; set; }
public string Name { get; set; }
}


public class ViewDetailResponse
{
List<ViewComments> CommentsList { get; set; }
}
public class ViewComments
{
public string Content { get; set; }
public ViewFileInfo AttachInfo;
}

public class ViewFileInfo
{
public string ID { get; set; }
public string Name { get; set; }
}

------- mapping profile

CreateMap<DetailsResponse, ViewDetailsResponse>();
CreateMap<FileInfo, ViewFileInfo>();
CreateMap<Comments, ViewComments>()
.ForMember(dest => dest.AttachInfo, act => act.MapFrom(src => src.AttachInfo)) ;

------ controller
public IActionResult GetData(Request request)

ViewDetailsResponse data = new ViewDetailsResponse();
var detailResponse = GetDetails(request);
data = _mapper.Map<DetailsResponse, ViewDetailsResponse>{detailResponse};

return Ok(data);


I can see from the data that AttachInfo is there with the values ID and Name but the json string is not showing in swagger

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,158 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 48,046 Reputation points
    2022-05-26T15:23:27.823+00:00

    AttachInfo is a field, not a property. The serializer isn't serializing fields.

    public class ViewComments
    {
    public string Content { get; set; }
    public ViewFileInfo AttachInfo { get; set; }
    }
    
    0 comments No comments

0 additional answers

Sort by: Most helpful