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

Response coming as string instead of object #2577

Open
gnanavinaymurari opened this issue Jul 19, 2024 · 1 comment
Open

Response coming as string instead of object #2577

gnanavinaymurari opened this issue Jul 19, 2024 · 1 comment

Comments

@gnanavinaymurari
Copy link

gnanavinaymurari commented Jul 19, 2024

Bug or question

mirage is giving string as response when we tried to return array in endpoint and it returns as object when we tried to return only one object from array:

Illustration:
I have below endpoints:

  1. this.get('/users/:id',function(schema,request){ return schema.users.findBy({id:request.params.id}) }
  2. this.get('/users',function(schema,request){ return schema.users.all() }

In test environment, both are working fine whereas in dev environment, second endpoint is giving response in string instead of an array.

@gnanavinaymurari
Copy link
Author

When we debug an issue in depth, we encounter a model like this:

{
    "name": "John Doe",
    "age": 30,
    "hobbies": ["reading", "coding", "hiking"],
    "address": {
        "street": "123 Main St",
        "city": "Anytown",
        "country": "USA"
    }
}

However, when it is returned from Mirage, it appears as:

{
    "name": "John Doe",
    "age": 30,
    "hobbies": '["reading", "coding", "hiking"]',
    "address": {
        "street": "123 Main St",
        "city": "Anytown",
        "country": "USA"
    }
}

The hobbies field is an array but is being returned as a string instead of being converted back to an array.

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

1 participant