Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem Serialising Array / Enumerable. #101

Open
robert-af opened this issue Sep 3, 2015 · 2 comments
Open

Problem Serialising Array / Enumerable. #101

robert-af opened this issue Sep 3, 2015 · 2 comments

Comments

@robert-af
Copy link

Version - 0.2.0.0 (nuget)

When serialising an array or enumerable, I get the following formatted output:

{
    "products":{
        "id":"NOIDCOMPUTABLE!",
        "length":3,
        "longLength":3,
        "rank":1,
        "isReadOnly":false,
        "isFixedSize":true,
        "isSynchronized":false,
        "links":{
            "syncRoot":"NOIDCOMPUTABLE!"
        }
    }

The class being serialised is:

[JsonObject(Title = "product")]
    public class ProductDto
    {
        public int Id { get; private set; }
        public string Name { get; private set; }

        public ProductDto(int id, string name)
        {
            Id = id;
            Name = name;
        }

        public override string ToString()
        {
            return string.Format("ProductDto [Id: {0}, Name: {1}]", Id, Name);
        }
    }

If I serialise one of these (instead of an array) I get the expected output:

{"products":{"id":"1","name":"bob"}}

This is running in a Web Api 2 project, with the following setup code in WebApiConfig.cs:

using JSONAPI.EntityFramework; // For pluralisation service.
using JSONAPI.Json;
// ...
var formatter = new JsonApiFormatter { PluralizationService = new PluralizationService() };
config.Formatters.Add(formatter);

Is there anything I am missing here? I've searched other open issues (and Stackoverflow) but couldn't see this mentioned anywhere.

Thanks.

@csantero
Copy link
Collaborator

csantero commented Sep 3, 2015

Sadly, the version on nuget is way out of date. For the time-being you should use the code that is in master. There is a little bit of documentation in #96 to help get you started.

@robert-af
Copy link
Author

Thanks very much. I'll give that a go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants