Skip to content

Commit

Permalink
Fix for Issue spring-attic#95 - Twitter userId is too large for JS se…
Browse files Browse the repository at this point in the history
…rialization

	Twitter provides id and id_str in User Object. Id is of datatype
	long and that could get too long for some programming languages
	to handle. For such languages, API is modified to return id in
	String format using the method getIdStr().
  • Loading branch information
kmohanarangam committed Jul 3, 2017
1 parent 515f251 commit 4b37c34
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
* Model class representing a Twitter user's profile information.
*
* @author Craig Walls
* @author karthik
*/
public class TwitterProfile extends TwitterObject implements Serializable {
private static final long serialVersionUID = 1L;

private final long id;
private final String idStr;
private final String screenName;
private final String name;
private final String url;
Expand Down Expand Up @@ -66,7 +68,12 @@ public static long getSerialversionuid() {
}

public TwitterProfile(long id, String screenName, String name, String url, String profileImageUrl, String description, String location, Date createdDate) {
this(id, String.valueOf(id), screenName, name, url, profileImageUrl, description, location, createdDate);
}

public TwitterProfile(long id, String idStr, String screenName, String name, String url, String profileImageUrl, String description, String location, Date createdDate) {
this.id = id;
this.idStr = idStr;
this.screenName = screenName;
this.name = name;
this.url = url;
Expand All @@ -85,6 +92,15 @@ public long getId() {
return id;
}

/**
* The user's Twitter ID in String format
*
* @return The user's Twitter ID in String format
*/
public String getIdStr() {
return idStr;
}

/**
* The user's Twitter screen name
*
Expand Down Expand Up @@ -422,6 +438,9 @@ public boolean equals(Object o) {
if (verified != that.verified) {
return false;
}
if (idStr != null ? !idStr.equals(that.idStr) : that.idStr != null) {
return false;
}
if (backgroundColor != null ? !backgroundColor.equals(that.backgroundColor) : that.backgroundColor != null) {
return false;
}
Expand Down Expand Up @@ -475,6 +494,7 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (idStr != null ? idStr.hashCode() : 0);
result = 31 * result + (screenName != null ? screenName.hashCode() : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (url != null ? url.hashCode() : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void getUserProfile() throws Exception {

TwitterProfile profile = twitter.userOperations().getUserProfile();
assertEquals(161064614, profile.getId());
assertEquals("161064614", profile.getIdStr());
assertEquals("artnames", profile.getScreenName());
assertEquals("Art Names", profile.getName());
assertEquals("I'm just a normal kinda guy", profile.getDescription());
Expand Down Expand Up @@ -100,6 +101,7 @@ public void getUserProfile_userId() throws Exception {

TwitterProfile profile = twitter.userOperations().getUserProfile(12345);
assertEquals(161064614, profile.getId());
assertEquals("161064614", profile.getIdStr());
assertEquals("artnames", profile.getScreenName());
assertEquals("Art Names", profile.getName());
assertEquals("I'm just a normal kinda guy", profile.getDescription());
Expand All @@ -117,6 +119,7 @@ public void getUserProfile_userId_appAuthorization() throws Exception {

TwitterProfile profile = appAuthTwitter.userOperations().getUserProfile(12345);
assertEquals(161064614, profile.getId());
assertEquals("161064614", profile.getIdStr());
assertEquals("artnames", profile.getScreenName());
assertEquals("Art Names", profile.getName());
assertEquals("I'm just a normal kinda guy", profile.getDescription());
Expand All @@ -133,6 +136,7 @@ public void getUserProfile_screenName() throws Exception {

TwitterProfile profile = twitter.userOperations().getUserProfile("artnames");
assertEquals(161064614, profile.getId());
assertEquals("161064614", profile.getIdStr());
assertEquals("artnames", profile.getScreenName());
assertEquals("Art Names", profile.getName());
assertEquals("I'm just a normal kinda guy", profile.getDescription());
Expand All @@ -150,6 +154,7 @@ public void getUserProfile_screenName_appAuthorization() throws Exception {

TwitterProfile profile = appAuthTwitter.userOperations().getUserProfile("artnames");
assertEquals(161064614, profile.getId());
assertEquals("161064614", profile.getIdStr());
assertEquals("artnames", profile.getScreenName());
assertEquals("Art Names", profile.getName());
assertEquals("I'm just a normal kinda guy", profile.getDescription());
Expand Down

0 comments on commit 4b37c34

Please sign in to comment.