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

IsMSISlice() doesn't work properly #7

Closed
an2deg opened this issue Sep 19, 2013 · 1 comment · Fixed by #85
Closed

IsMSISlice() doesn't work properly #7

an2deg opened this issue Sep 19, 2013 · 1 comment · Fixed by #85

Comments

@an2deg
Copy link

an2deg commented Sep 19, 2013

Hi!

I have the following JSON structure:

{"d":[{"author":{"displayName":"DemoUser3","id":2},"classes":null,"id":9879,"v":{"code":"","created":"2013-09-19T09:38:50+02:00","published":"0001-01-01T00:00:00Z","updated":"2013-09-19T09:38:50+02:00"}}],"s":200}

And method IsMSISlice() returns false. Test:

    json, err := objx.FromJSON(`{"d":[{"author":{"displayName":"DemoUser3","id":2},"classes":null,"id":9879,"v":{"code":"","created":"2013-09-19T09:38:50+02:00","published":"0001-01-01T00:00:00Z","updated":"2013-09-19T09:38:50+02:00"}}],"s":200}`)

    if !assert.NoError(t, err, "Can't decode output") {
        return
    }
    assert.True(t, json.Has("d"), json.MustJSON())

    if !assert.True(t, json.Get("d").IsMSISlice(), json.MustJSON()) {
        return
    }
    if !assert.Equal(t, 1, len(json.Get("d").MSISlice()), "...") {
        return
    }
@tylerstillwater
Copy link
Contributor

The JSON unmarshaller unpacks all slices to []interface{}. To make it an MSI, I think we'd have to iterate and copy to the new slice.

@hanzei hanzei self-assigned this Jan 29, 2018
@hanzei hanzei added the bug label Jan 29, 2018
@hanzei hanzei added this to the v0.2 milestone Jan 29, 2018
@hanzei hanzei removed their assignment Oct 12, 2018
@geseq geseq mentioned this issue Feb 1, 2019
@hanzei hanzei closed this as completed in #85 Feb 4, 2019
hanzei pushed a commit that referenced this issue Feb 4, 2019
Fixes #7 

ObjxMapSlice() and MSISlice() casting was already fixed in my previous pull requests. However, the checks in IsObjxMapSlice() and IsMSISlice() weren't.

Fixed and added new tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants