how would i encode a primative array of objects?

May 3, 2011 at 7:01 PM

like this ?

 

IJsonEncoder<PageName[]> encoder = Json.EncoderFor<PageName[]>(config => config
                .Map(map => map
                    .AllFields()
                    ).UseTidy(true)
                    );

 

when i call : return encoder.Encode(pagePeople);

i get a StackOverflowException : "System.StackOverflowException was unhandled"

 

my PageName class

public class PageName
{
     public string PageText { get; set; }
     public string SAMAccountName { get; set; }
     public string Telephone { get; set; }
}

May 3, 2011 at 7:15 PM

I tried it with a List<PageName> and it gave a different error

{"Parameter count mismatch."}

IJsonEncoder<List<PageName>> encoder = Json.EncoderFor<List<PageName>>(config => config
                .Map(map => map
                    .AllFields()
                    )
                    );

May 3, 2011 at 7:21 PM

did not work when i added the List<PageName> to an anonymous object ...

BUT it worked once I added the PageName list to a new object ... heres the working code

public class PageNameBase
{
    public List<PageName> Names { get; set; }
}
public class PageName
{
    public string PageText { get; set; }
    public string SAMAccountName { get; set; }
    public string Telephone { get; set; }
}

IJsonEncoder<PageNameBase> encoder = Json.EncoderFor<PageNameBase>(config => config
                .Map(map => map
                    .AllFields()
                    )
                    .MapType<PageName>(map => map
                        .AllFields()
                        )
                    );

            populateFromLdap(pagePeople);

            return encoder.Encode(new PageNameBase { Names = pagePeople.ToList() });

Coordinator
May 10, 2011 at 4:59 PM

Sorry for the late reply. Will be uploading version 0.7 later today, these issues are all fixed now.