twitter4j.json
Class DataObjectFactory

java.lang.Object
  extended by twitter4j.json.DataObjectFactory

public final class DataObjectFactory
extends java.lang.Object

Since:
Twitter4J 2.1.7
Author:
Yusuke Yamamoto - yusuke at mac.com

Field Summary
private static java.lang.reflect.Constructor<AccountTotals> accountTotalsConstructor
           
private static java.lang.reflect.Constructor<Category> categoryConstructor
           
private static java.lang.reflect.Constructor<DirectMessage> directMessageConstructor
           
private static java.lang.reflect.Constructor<IDs> IDsConstructor
           
private static boolean JSON_STORE_ENABLED
           
private static java.lang.reflect.Constructor<Location> locationConstructor
           
private static java.lang.reflect.Constructor<Place> placeConstructor
           
private static java.lang.reflect.Constructor<RateLimitStatus> rateLimitStatusConstructor
           
private static java.lang.ThreadLocal<java.util.Map> rawJsonMap
           
private static java.lang.reflect.Constructor<RelatedResults> relatedResultsConstructor
           
private static java.lang.reflect.Constructor<Relationship> relationshipConstructor
           
private static java.lang.reflect.Constructor<SavedSearch> savedSearchConstructor
           
private static java.lang.reflect.Constructor<Status> statusConstructor
           
private static java.lang.reflect.Constructor<StatusDeletionNotice> statusDeletionNoticeConstructor
           
private static java.lang.reflect.Constructor<Trend> trendConstructor
           
private static java.lang.reflect.Constructor<Trends> trendsConstructor
           
private static java.lang.reflect.Constructor<Tweet> tweetConstructor
           
private static java.lang.reflect.Constructor<User> userConstructor
           
private static java.lang.reflect.Constructor<UserList> userListConstructor
           
 
Constructor Summary
private DataObjectFactory()
           
 
Method Summary
(package private) static void clearThreadLocalMap()
          clear raw JSON forms associated with the current thread.
Currently this method is called indirectly by twitter4j.internal.util.DataObjectFactoryUtil, and should be called directly once *JSONImpl classes are migrated to twitter4j.json.* package.
static AccountTotals createAccountTotals(java.lang.String rawJSON)
          Constructs an AccountTotals object from rawJSON string.
static Category createCategory(java.lang.String rawJSON)
          Constructs a Category object from rawJSON string.
static DirectMessage createDirectMessage(java.lang.String rawJSON)
          Constructs a DirectMessage object from rawJSON string.
static IDs createIDs(java.lang.String rawJSON)
          Constructs a IDs object from rawJSON string.
static Location createLocation(java.lang.String rawJSON)
          Constructs a Location object from rawJSON string.
static java.lang.Object createObject(java.lang.String rawJSON)
          Construct an object from rawJSON string.
static Place createPlace(java.lang.String rawJSON)
          Constructs a Place object from rawJSON string.
static RateLimitStatus createRateLimitStatus(java.lang.String rawJSON)
          Constructs a RateLimitStatus object from rawJSON string.
static RelatedResults createRelatedResults(java.lang.String rawJSON)
          Constructs a RelatedResults object from rawJSON string.
static Relationship createRelationship(java.lang.String rawJSON)
          Constructs a Relationship object from rawJSON string.
static SavedSearch createSavedSearch(java.lang.String rawJSON)
          Constructs a SavedSearch object from rawJSON string.
static Status createStatus(java.lang.String rawJSON)
          Constructs a Status object from rawJSON string.
static Trend createTrend(java.lang.String rawJSON)
          Constructs a Trend object from rawJSON string.
static Trends createTrends(java.lang.String rawJSON)
          Constructs a Trends object from rawJSON string.
static Tweet createTweet(java.lang.String rawJSON)
          Constructs a Tweet object from rawJSON string.
static User createUser(java.lang.String rawJSON)
          Constructs a User object from rawJSON string.
static UserList createUserList(java.lang.String rawJSON)
          Constructs a UserList object from rawJSON string.
static java.lang.String getRawJSON(java.lang.Object obj)
          Returns a raw JSON form of the provided object.
Note that raw JSON forms can be retrieved only from the same thread invoked the last method call and will become inaccessible once another method call
(package private) static
<T> T
registerJSONObject(T key, java.lang.Object json)
          associate a raw JSON form to the current thread
Currently this method is called indirectly by twitter4j.internal.util.DataObjectFactoryUtil, and should be called directly once *JSONImpl classes are migrated to twitter4j.json.* package.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JSON_STORE_ENABLED

private static final boolean JSON_STORE_ENABLED

statusConstructor

private static final java.lang.reflect.Constructor<Status> statusConstructor

userConstructor

private static final java.lang.reflect.Constructor<User> userConstructor

tweetConstructor

private static final java.lang.reflect.Constructor<Tweet> tweetConstructor

relationshipConstructor

private static final java.lang.reflect.Constructor<Relationship> relationshipConstructor

placeConstructor

private static final java.lang.reflect.Constructor<Place> placeConstructor

savedSearchConstructor

private static final java.lang.reflect.Constructor<SavedSearch> savedSearchConstructor

trendConstructor

private static final java.lang.reflect.Constructor<Trend> trendConstructor

trendsConstructor

private static final java.lang.reflect.Constructor<Trends> trendsConstructor

IDsConstructor

private static final java.lang.reflect.Constructor<IDs> IDsConstructor

rateLimitStatusConstructor

private static final java.lang.reflect.Constructor<RateLimitStatus> rateLimitStatusConstructor

categoryConstructor

private static final java.lang.reflect.Constructor<Category> categoryConstructor

directMessageConstructor

private static final java.lang.reflect.Constructor<DirectMessage> directMessageConstructor

locationConstructor

private static final java.lang.reflect.Constructor<Location> locationConstructor

userListConstructor

private static final java.lang.reflect.Constructor<UserList> userListConstructor

relatedResultsConstructor

private static final java.lang.reflect.Constructor<RelatedResults> relatedResultsConstructor

statusDeletionNoticeConstructor

private static final java.lang.reflect.Constructor<StatusDeletionNotice> statusDeletionNoticeConstructor

accountTotalsConstructor

private static final java.lang.reflect.Constructor<AccountTotals> accountTotalsConstructor

rawJsonMap

private static final java.lang.ThreadLocal<java.util.Map> rawJsonMap
Constructor Detail

DataObjectFactory

private DataObjectFactory()
Method Detail

getRawJSON

public static java.lang.String getRawJSON(java.lang.Object obj)
Returns a raw JSON form of the provided object.
Note that raw JSON forms can be retrieved only from the same thread invoked the last method call and will become inaccessible once another method call

Parameters:
obj -
Returns:
raw JSON
Since:
Twitter4J 2.1.7

createStatus

public static Status createStatus(java.lang.String rawJSON)
                           throws TwitterException
Constructs a Status object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
Status
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createUser

public static User createUser(java.lang.String rawJSON)
                       throws TwitterException
Constructs a User object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
User
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createAccountTotals

public static AccountTotals createAccountTotals(java.lang.String rawJSON)
                                         throws TwitterException
Constructs an AccountTotals object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
AccountTotals
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.9

createTweet

public static Tweet createTweet(java.lang.String rawJSON)
                         throws TwitterException
Constructs a Tweet object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
Tweet
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createRelationship

public static Relationship createRelationship(java.lang.String rawJSON)
                                       throws TwitterException
Constructs a Relationship object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
Relationship
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createPlace

public static Place createPlace(java.lang.String rawJSON)
                         throws TwitterException
Constructs a Place object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
Place
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createSavedSearch

public static SavedSearch createSavedSearch(java.lang.String rawJSON)
                                     throws TwitterException
Constructs a SavedSearch object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
SavedSearch
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createTrend

public static Trend createTrend(java.lang.String rawJSON)
                         throws TwitterException
Constructs a Trend object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
Trend
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createTrends

public static Trends createTrends(java.lang.String rawJSON)
                           throws TwitterException
Constructs a Trends object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
Trends
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createIDs

public static IDs createIDs(java.lang.String rawJSON)
                     throws TwitterException
Constructs a IDs object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
IDs
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createRateLimitStatus

public static RateLimitStatus createRateLimitStatus(java.lang.String rawJSON)
                                             throws TwitterException
Constructs a RateLimitStatus object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
RateLimitStatus
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createCategory

public static Category createCategory(java.lang.String rawJSON)
                               throws TwitterException
Constructs a Category object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
Category
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createDirectMessage

public static DirectMessage createDirectMessage(java.lang.String rawJSON)
                                         throws TwitterException
Constructs a DirectMessage object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
DirectMessage
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createLocation

public static Location createLocation(java.lang.String rawJSON)
                               throws TwitterException
Constructs a Location object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
Location
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createUserList

public static UserList createUserList(java.lang.String rawJSON)
                               throws TwitterException
Constructs a UserList object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
UserList
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.7

createRelatedResults

public static RelatedResults createRelatedResults(java.lang.String rawJSON)
                                           throws TwitterException
Constructs a RelatedResults object from rawJSON string.

Parameters:
rawJSON - raw JSON form as String
Returns:
RelatedResults
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.8

createObject

public static java.lang.Object createObject(java.lang.String rawJSON)
                                     throws TwitterException
Construct an object from rawJSON string. This method may be called when you do not know what a given raw JSON string contains. It will do the work of determining what type of object the JSON represents, and constructing the respective object type. For example, if the JSON contents represents a Status, then a Status will be returned. If it represents a deletion notice, then a StatusDeletionNotice will be returned. The caller can simply use instanceof to handle the returned object as applicable. NOTE: the raw JSONObject will be returned in cases where there isn't a discrete respective object type that can be constructed. That way, the caller can at least have access to the JSON itself.

Parameters:
rawJSON - raw JSON form as String
Returns:
the respective constructed object, or the JSONObject in the case where we cannot determine the object type.
Throws:
TwitterException - when provided string is not a valid JSON string.
Since:
Twitter4J 2.1.9

clearThreadLocalMap

static void clearThreadLocalMap()
clear raw JSON forms associated with the current thread.
Currently this method is called indirectly by twitter4j.internal.util.DataObjectFactoryUtil, and should be called directly once *JSONImpl classes are migrated to twitter4j.json.* package.

Since:
Twitter4J 2.1.7

registerJSONObject

static <T> T registerJSONObject(T key,
                                java.lang.Object json)
associate a raw JSON form to the current thread
Currently this method is called indirectly by twitter4j.internal.util.DataObjectFactoryUtil, and should be called directly once *JSONImpl classes are migrated to twitter4j.json.* package.

Since:
Twitter4J 2.1.7