I have below json
"PayloadData": {
"CustomFields": ['test','test2'],
"SampleNumber":"123"
}
I am using below code to deserialize the json.
Message message = JsonConvert.DeserializeObject<Message>(payloadData);
Here is my property in Message
class
/// <summary>
/// Gets or sets CustomFields
/// </summary>
[Required]
[DataMember(Name = "CustomFields")]
public List<string> CustomFields{ get; set; }
But, I get below error.
"The property 'Message.CustomFields' could not be mapped, because it is of type 'string[]' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'."
You can try using this online json to C# class generator to get the structure of a POCO required to deserialize a json string.
Then simply map it to your EF class (using AutoMapper for example):
So for this JSON:
{
"CustomFields": ['test','test2'],
"SampleNumber":"123"
}
this is the POCO that is generated:
public class RootObject
{
public List<string> CustomFields { get; set; }
public string SampleNumber { get; set; }
}
if this is your actual JSON:
{ "PayloadData":
{
"CustomFields": ['test','test2'],
"SampleNumber":"123"
}
}
this is how your POCO is supposed to look like:
public class PayloadData
{
public List<string> CustomFields { get; set; }
public string SampleNumber { get; set; }
}
public class RootObject
{
public PayloadData PayloadData { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With