I'm trying to serialize class Poll, which looks like that:
class Poll
{
(...) //methods
public AnswersCollection answers { get; set; }
public TagsCollection tags { get; set; }
public string question { get; set; }
}
As you can see, I have "TagsCollection" and "AnswersCollection", which both look pretty similiar, so I'll show only one of them.
class AnswersCollection
{
(...) //methods
public List<Answer> answers { get; set; }
}
And, finnaly, Answer class.
class Answer
{
(...) //methods
public string name { get; set; }
public uint voteQuantity { get; set; }
}
All clases have default public constructor (without parameters) so JSON.NET doesn't have any problems with serialization.
Problem is with AnswersCollection (which is encapsulation), because of it, JSON output looks like that:
{
"answers":{
"answers":[
{
"name":"Foo",
"voteQuantity":45
},
{
"name":"Bar",
"voteQuantity":30
}
]
},
"tags":{
"tags":[
{
"name":"FooTag",
"id":5
},
{
"name":"BarTag",
"id":4
}
]
},
"question":"Question?"
}
As you can see, the problem is with structures like "answers":{ "answers": [(...)] }
Is there option to serialize it to structures like "answers" :[(...)] without second "answers" tag? I tried to use properties like "isReference" but it didn't worked.