forked from hatboysam/JavaSnap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSON Binding Interface and Friend Object
- Loading branch information
Showing
5 changed files
with
102 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.habosa.javasnap; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Author: samstern | ||
* Date: 12/31/13 | ||
*/ | ||
public class Friend implements JSONBinder<Friend> { | ||
|
||
private static final String USERNAME_KEY = "name"; | ||
private static final String DISPLAY_NAME_KEY = "display"; | ||
|
||
private String username; | ||
private String displayName; | ||
|
||
public Friend() { } | ||
|
||
public Friend bind(JSONObject obj) { | ||
try { | ||
this.username = obj.getString(USERNAME_KEY); | ||
this.displayName = obj.getString(DISPLAY_NAME_KEY); | ||
} catch (JSONException e) { | ||
return this; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getDisplayName() { | ||
return displayName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return username + " ~> " + displayName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.habosa.javasnap; | ||
|
||
import org.json.JSONObject; | ||
|
||
/** | ||
* Author: samstern | ||
* Date: 12/31/13 | ||
*/ | ||
public interface JSONBinder<T> { | ||
|
||
public T bind(JSONObject obj); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters