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

Getting a User object with null fields fails #9

Closed
Kissaki opened this issue Jun 23, 2013 · 6 comments
Closed

Getting a User object with null fields fails #9

Kissaki opened this issue Jun 23, 2013 · 6 comments

Comments

@Kissaki
Copy link

Kissaki commented Jun 23, 2013

The github API v3 declares that blank fields are included with a null as the value instead of being omitted.

For a user which did not specify an organisation, blog or bio the Get returns null as the field values.
In go-github this leads to an unmarshalling failure as type string is defined in the struct type User. Unfortunately, null can not be unmarshalled/mapped to string.

A potential solution may be to change the type from string to pointers, allowing nil.
But then this should probably be implemented as a general concept across the library, as the API docs state that generally empty fields are returned as null values - and does not seem to note which fields can be empty/null in the end.

@willnorris
Copy link
Collaborator

Are you actually seeing these marshaling errors in practice? I've tried writing a sample test that causes an error, but am unable. Could you post an example, either here or in a pull request?

@Kissaki
Copy link
Author

Kissaki commented Jun 23, 2013

A simple script that leads to the unmarshalling error:

package main

import (
    "log"
    githubapi "github.com/google/go-github/github"
)

func main() {
    github := githubapi.NewClient(nil)
    uname := "Kissaki"
    _, err := github.Users.Get(uname)
    if err != nil {
        log.Fatalf("Failed to find user %s. Error: %s\n", uname, err)
    } else {
        log.Printf("Found user %s\n", uname)
    }
}

@willnorris
Copy link
Collaborator

running that script, I get:

% go run main.go
2013/06/23 10:23:37 Found user Kissaki

What version of Go are you running? I've tried both 1.0.3 and 1.1, and neither throw an error for me.

@Kissaki
Copy link
Author

Kissaki commented Jun 23, 2013

I’m running a 1.0.3 on Windows 7 x64 here.

@Kissaki
Copy link
Author

Kissaki commented Jun 29, 2013

With Go 1.1.1 on Windows 7 x64 this is no longer an issue.
I guess the behaviour changed from Go version 1.0 to 1.1.

So unless functionality for Go 1.0 is a goal here, I’m fine with closing this.

@willnorris
Copy link
Collaborator

ah, cool... thanks for following up on this. I'll close this out, but maybe we can start a "known issues" page somewhere, and mention this.

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