0

I have a class object:

public class ChildDetails
{
    [JsonProperty("idConsecutivo")]
    public int SequentialId { get; set; }
    [JsonProperty("idSemilla")]
    public int ParentId { get; set; }
    [JsonProperty("idParentSemilla")]
    public int ChildId { get; set; }
    [JsonProperty("NombreArchivo")]
    public string FileName { get; set; }        
}

When execute this line:

var childItems = JsonConvert.DeserializeObject<List<ChildDetails>>(resultContent);

childItems object property names are: SequentialId, ParentId, ChildId and FileName

but when execute this line:

var otherChildItems = JsonConvert.SerializeObject(childItems);

otherChildItems object property names are: idConsecutivo, idSemilla, idParentSemilla, NombreArchivo

How to keep the property names SequentialId, ParentId, ChildId and FileName when object is serialized?

Thanks

ericardezp
  • 29
  • 1
  • 6
  • If you need to serialize using one set of names and deserialize using a different set of names, then you might want to check out this answer: http://stackoverflow.com/questions/22993576/jsonproperty-use-different-name-for-deserialization-but-use-original-name-for – dontangg Oct 13 '15 at 22:47

1 Answers1

0

To keep regular property names simply don't add JsonProperty attributes that allow you to specify alternative name:

public class ChildDetails
{
    public int SequentialId { get; set; }
    ...
}
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179