I'm having an issue where I am trying to post a class I have with several properties and there are properties that are of type List that are for some reason not POSTing on the server.
This is an example JSON of an item from the webserver
{
"at": "AA",
"campaign": "Unknown",
"createdby": {
"userid": "user001",
"writetime": "2021-06-13T23:43:21.600446Z"
},
"geographies": [
{
"country": "USA",
"province": "New York",
"city": "Albany",
"createdby": {
"userid": "user001",
"writetime": "2020-06-17T15:46:45.214185Z"
},
"id": "db3faf37-88d3-46fd-8ca5-54898c3450fc",
"source": "Manual Entry",
"userid": ""user001",",
"writetime": "2020-06-17T15:46:45.214185Z"
}
],
"isVerified": true,
"isValid": false,
"platforms": [],
"remarks": {},
"roe": "001",
"dtg": "2021-06-13T16:42:00Z",
"identifier": "10101",
"type": "DELIBERATE",
"id": "cd4e2c93-4215-466c-b680-044a094477b5",
"rowid": "e70e9253-1946-4497-ba8e-58216c1a1e39",
"source": "Manual Entry",
"userid": "user001",
"writetime": "2021-06-13T23:43:21.600446Z",
"readgroups": [
"public"
],
"writegroups": [
"public"
],
"classification": {
"level": "0",
"aea": {
"value": ""
},
"classificationString": "",
"portionString": ""
}
}
When I create my own item using a C# class, I serialize it and this is what it looks like
{
"at": "FE",
"campaign": "Unknown",
"createdby": {
"userid": "user001",
"writetime": "2021-06-27T12:00:00"
},
"geographies": [
{
"country": "USA",
"province": "Florida",
"city": "Miami",
"createdby": {
"userid": "user001",
"writetime": "2021-06-27T12:00:00"
},
"id": "db3faf37-88d3-46fd-8ca5-54898c3450fc",
"source": "Manual Entry",
"userid": "user001",
"writetime": "0001-01-01T00:00:00"
}
],
"isVerified": true,
"isValid": false,
"munitions": [],
"operation": null,
"platforms": [],
"remarks": {
"remark1": null,
"remark2": null
},
"roe": "009",
"dtg": "2021-06-27T12:00:00",
"identifier": "77896",
"type": "DYNAMIC",
"unit": null,
"id": "cd4e2c93-4215-466c-b680-044a094477b5",
"rowid": "e70e9253-1946-4497-ba8e-58216c1a1e39",
"source": null,
"userid": "user001",
"writetime": "0001-01-01T00:00:00",
"readgroups": [
"public"
],
"writegroups": [
"public"
],
"classification": null
}
And the result from the post is successful, and I see it on the webserver but the geography is not being posted for some reason.
This is my C# code if that helps
MyItemClass item;
item = new MyItemClass
{
id = _id,
rowid = _rowid,
at = _at,
campaign = _campaign,
isVerified = _verified,
isValid = _valid,
operation = _operation,
roe = _roe,
dtg = _dtg,
identifier = _identifier,
type = _type,
unit = _unit,
userid = _userId,
createdby = new CreatedByClass()
{
userid = _userId,
writetime = _writetime
},
remarks = new RemarksClass()
{
remark1 = _rem1,
remark2 = _rem2
},
readgroups = new List<string>() { "public" },
writegroups = new List<string>() { "public" },
geographies = new List<Geography>(),
platforms = new List<Platform>(),
};
// import Location data
foreach (LocationsModel location in ListOfLocations)
{
if (location.SelectedCity == null)
location.SelectedCity = string.Empty;
if (location.SelectedProvince == null)
location.SelectedProvince = string.Empty;
item.geographies.Add(new Geography()
{
city = location.SelectedCity,
country = location.SelectedCountry,
province = location.SelectedProvince,
id = location.LocationGuid.ToString(),
userid = _userid,
source = _source,
createdby = new CreatedByClass()
});
}
string ItemJsonString = JsonConvert.SerializeObject(item);
JObject data = JObject.Parse(ItemJsonString);
string newJson = data.ToString();
var Content = new StringContent(newJson, Encoding.UTF8, "application/json");
var result = httpClient?.PostAsync($"<URL>", Content).Result;
From sources online, there are few ways I saw how to perform a POST and this is one of them, but from what I have tried, none of them have worked and I'm not sure why.