Package twitter4j

Class TwitterObjectFactory

java.lang.Object
twitter4j.TwitterObjectFactory

public final class TwitterObjectFactory extends Object
Since:
Twitter4J 4.0.0
  • Method Details

    • getRawJSON

      public static String getRawJSON(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 - target object to retrieve JSON
      Returns:
      raw JSON
      Since:
      Twitter4J 2.1.7
    • createStatus

      public static Status createStatus(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(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(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
    • createRelationship

      public static Relationship createRelationship(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(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(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(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(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(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 Map<String,RateLimitStatus> createRateLimitStatus(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
    • createDirectMessage

      public static DirectMessage createDirectMessage(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(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(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
    • createOEmbed

      public static OEmbed createOEmbed(String rawJSON) throws TwitterException
      Constructs an OEmbed object from rawJSON string.
      Parameters:
      rawJSON - raw JSON form as String
      Returns:
      OEmbed
      Throws:
      TwitterException - when provided string is not a valid JSON string.
      Since:
      Twitter4J 3.0.2
    • createObject

      public static Object createObject(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