javaspringrestspring-social-twitter

In Spring Social Tweeter, how does JSON become a Tweet, and how does RestTemplate.getObject<T> work?


everybody.

In Spring Social Twitter we use RestTemplate.getObject<T>() to retrieve and deserialize data from the REST endpoint. It does its job and it is very neat! But how does it do that?

How can the JSON (source 1) be translated into the .JAVA (source 2).

This question has come up when I noticed that "coordinates" is inside TweetData, not as an attribute of Tweet.

Thanks for the help in advance!

EDIT I found out the class that does the deserialization and the answer and posted it up thanks to Mr. @Sotirios Delimanolis hint.


Solution

  • Following @Sotirios Delimanolis, I digged around to find how the HttpMessageConverter worked. And the HttpMessageConverter is in fact used by most of the deserialization in the Spring Social Twitter api.

    However, for Tweets (whose JSON varies a lot from the Tweet.java structure), I have found that we use an object called TweetDeserializer.java (self explainable, right?)

    The aswer, therefore, lies here:

    https://github.com/spring-projects/spring-social-twitter/blob/master/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/TweetDeserializer.java

    Craig Walls describes it in the file docs:

    Custom Jackson deserializer for tweets. Tweets can't be simply mapped like other Twitter model objects because the JSON structure varies between the search API and the timeline API. This deserializer determine which structure is in play and creates a tweet from it. @author Craig Walls

    I'm sorry for bothering you guys with this silly question, but I feel that pushing this answer up here might help people landing in Spring development to find their way around.