'Android Retrofit2 calls to aspnet webapi are not triggering post when @SerializedName is added, but not passing object w/o it
I am trying to POST to a dotnet webapi from android retrofit. When I POST an object I am getting to the controller (I see the log entries in the console), but no values are getting passed. When I add @SerializedName, as I have had to do in other calls, the call is not even triggering the webapi controller post method.
My webapi controller looks like this:
[HttpPost]
public async Task<ActionResult<PageResults<TokenExchangeDTO>>> Post([FromBody] SearchFilter searchFilter)
{
_logger.LogDebug("Debug Post");
_logger.LogDebug("Post called: SearchPhrase=" + searchFilter.SearchPhrase +
";PageNumber=" + searchFilter.PageNumber + ";PageSize=" + searchFilter.PageSize);
return Ok(await Search(searchFilter));
}
I am trying to use this object as the input for the call:
public class PagingSearchDto {
@SerializedName("searchPhrase")
private String searchPhrase;
@SerializedName("pageNumber")
private int pageNumber;
@SerializedName("pageSize")
private int pageSize;
public void setSearchPhrase (String searchPhrase) { this.searchPhrase=searchPhrase; }
public String getSearchPhrase() { return this.searchPhrase; }
public void setPageNumber (int pageNumber) { this.pageNumber=pageNumber; }
public int getPageNumber() { return this.pageNumber; }
public void setPageSize(int pageSize) { this.pageSize=pageSize; }
public int getPageSize() { return this.pageSize; }
}
When I comment out the @SerializedName statements I can see the aspnet logging statements, but the object values are empty. When I add @SerializedName it looks like they don't get triggered at all.
I can see there is a request of some sort as I have ApplicationInsights on the dotnet webapi, so the request is seemingly made.
I have another POST working and set this one up in the exact same manner and this seems like strange behavior and hard to diagnose. I am following all the documentation and even have a working example in another POST.
I have an interceptor and see the post looks like this:
[PagingSearchDto{searchPhrase='', pageNumber=1, pageSize=10}]
I wish I could make it this to test:
{searchPhrase='', pageNumber=1, pageSize=10}
Is there any way to control how the json at the class level?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
