question

Cris-1247 avatar image
0 Votes"
Cris-1247 asked cooldadtx answered

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

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

dotnet-aspnet-core-generaldotnet-aspnet-core-webapi
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered

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; }
}
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.