1
I’m creating a API
, POST method, where the payload
consists of 3 classes with the following structure:
//Classe principal do payload
public class Representante
{
[JsonProperty(PropertyName = "representatives")]
public List<Representante> Representantes { get; set; }
}
//Classe que compõe o tipo da lista acima
[JsonObject(Title = "Representative")]
public class Representante
{
[JsonProperty(PropertyName = "personCode")]
public string CodigoPessoa { get; set; }
[JsonProperty(PropertyName = "cpf")]
public string Cpf { get; set; }
[JsonProperty(PropertyName = "name")]
public string Nome { get; set; }
[JsonProperty(PropertyName = "clientPart")]
public ClienteParte ClienteParte { get; set; }
}
//Classe referente ao objeto que compõe a classe 'Representante'
[JsonObject(Title = "clientPart")]
public class ClienteParte
{
[JsonProperty(PropertyName = "name")]
public string Nome { get; set; }
[JsonProperty(PropertyName = "numberDocument")]
public string NumeroDocumento { get; set; }
}
When performing a test to validate whether everything I reported on payload
below reflects on the input objects, I noticed that the object ClienteParte ("clientPart")
is returned with null value. I need to inform a different structure in Propertyname to understand that the property belongs to one class within another classe?
Example: [JsonProperty(PropertyName="clientPart.name")]
Payload:
{
"sellerCode":332,
"representatives": [ {
"personCode": 41333440,
"cpf": 67788947687,
"name": "TAPIXU ENMU FIHJAE",
"signatureType": "C",
"clientPart": [{
"name":" JOAO DA SILVA",
"numberDocument ":"67826789372"
}],
}]
}
Return reflected in input class:
I think you just got a little confused, look at the json, the clientpart is in brackets, I mean, it’s a list, in your Representative class it’s just an object
– Lucas Miranda
clientPart
is poorly formed, has a left comma and keynumberDocument
has a space inside between thet
and the"
.– Augusto Vasques
The error was in the same brackets. I fixed it here and it worked. Thank you!
– Anderson Anselmo