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

weird format for get list of organizations #291

Closed
marti1125 opened this issue Aug 5, 2016 · 4 comments
Closed

weird format for get list of organizations #291

marti1125 opened this issue Aug 5, 2016 · 4 comments

Comments

@marti1125
Copy link

GitHub gh = GitHub.connect("login", "token");
System.out.println(gh.getMyOrganizations());

How to I can parse this? =/

{mozillaperu=GHOrganization@29ba4338[login=mozillaperu,location=,blog=,email=,name=,company=,followers=0,following=0,url=https://api.github.com/orgs/mozillaperu,id=1221419], qillu=GHOrganization@57d5872c[login=qillu,location=,blog=,email=,name=,company=,followers=0,following=0,url=https://api.github.com/orgs/qillu,id=16871604], eknowit=GHOrganization@667a738[login=eknowit,location=,blog=,email=,name=,company=,followers=0,following=0,url=https://api.github.com/orgs/eknowit,id=1102009], VulpesTools=GHOrganization@36f0f1be[login=VulpesTools,location=,blog=,email=,name=,company=,followers=0,following=0,url=https://api.github.com/orgs/VulpesTools,id=8617634], GenerationOpen=GHOrganization@157632c9[login=GenerationOpen,location=,blog=,email=,name=,company=,followers=0,following=0,url=https://api.github.com/orgs/GenerationOpen,id=4251591], mozillahispano=GHOrganization@6ee12bac[login=mozillahispano,location=,blog=,email=,name=,company=,followers=0,following=0,url=https://api.github.com/orgs/mozillahispano,id=1511160], mozilla-appmaker=GHOrganization@55040f2f[login=mozilla-appmaker,location=,blog=,email=,name=,company=,followers=0,following=0,url=https://api.github.com/orgs/mozilla-appmaker,id=5852021]}

@marti1125 marti1125 changed the title weird format for get list of oganizations weird format for get list of organizations Aug 5, 2016
@Shredder121
Copy link
Contributor

In most cases, the toString of object shouldn't be used for parsing.

http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

Emphasis mine.

@kohsuke
Copy link
Collaborator

kohsuke commented Aug 6, 2016

Indeed, toString() is for debug assistance only.

@kohsuke kohsuke closed this as completed Aug 6, 2016
@marti1125
Copy link
Author

@kohsuke I don't expected this answer. I would like to how to parse that data?

@Shredder121
Copy link
Contributor

@marti1125 Rule of thumb, if a class has a valueOf(String) method, its toString() method can be used for machine consumption.
GHOrganization doesn't have one, so the toString() is really only for debug assistance.

You could hack something together with regex to match all between [ and ], split on ,, then setting all fields via reflection.

I do however want to refer to the first paragraph on this site:
http://www.javapractices.com/topic/TopicAction.do?Id=55

The toString method is widely implemented. It provides a simple, convenient mechanism for debugging classes during development. It's also widely used for logging, and for passing informative error messages to Exception constructors and assertions. When used in these informal ways, the exact format of toString is not part of the contract of the method, and callers should not rely on the exact format of the returned String.

Emphasis mine.

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

3 participants