Search code examples
javajsontwitter4j

twitter4j 4.0.2 getRawJSON() returns null


I'm trying to save the tweets I got as JSON objects and however still unable to get the JSON object out of Status objects. I have checked JSONStoreEnabled() and it's set to true.

API says,

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.

I have my everything inside the main() method, so I guess this shouldn't be an issue.

String tweet = TwitterObjectFactory.getRawJSON( status );

I have checked that the status object contains all the information and it's just that getRawJSON returns null!. Really appreciate if someone can tell me a fix for this.


Solution

  • This is it.

             Gson gson = new Gson();
             String json = gson.toJson( status );
             System.out.println( json );