Using our tools we are able to easily see the request generated by our server. It is huge. By default, Jackson, the JSON serialization library used by Spring Boot, will serialize everything that is accessible with a getter method.
We would like something lighter, such as this:
{ "text": "original text", "user": "some_dude", "profileImageUrl": "url", "lang": "en", "date": 2015-04-15T20:18:55, "retweetCount": 42 }
The easiest way to customize which fields will be serialized is by adding annotations to our beans. You can either use the @JsonIgnoreProperties
annotation at the class level to ignore a set of properties or add @JsonIgnore
on the getters of the properties you wish to ignore.
In our case, the Tweet
class is not one of our own. It is part of Spring Social Twitter, and we do not have the ability to annotate it.
Using the model classes directly for serialization is rarely a good option. It would tie your model to your serialization library, which...