Thursday, April 7, 2016

Improve your performance with Spring Cache

Spring provides and abstraction layer to work with different cache providers. It is very useful to improve the performance of your software avoiding to compute data already calculated and without any state change. To learn more about this, you can check the Spring documentation here.

In the next screencast you can see a simple example of use of the different annotations supported by Spring Cache abstraction.


I hope you will find it interesting.

Monday, April 4, 2016

Serializing views with Jackson

As the title of this article says, you can define different views of the object which you want to serialize, typically the response of a REST service.

For example, you can define a view called Summary and at the same time another called Complete. Le't me show you with a code example.

First of all, you have to define, in your DTO, the required views. In this case we have two views, MessageSummary and MessageEntire.



Note that the class used to define your views is an interface which includes other interfaces. Also is important to note, that the MessageEntire view extends from MessageSummary, then all fields marked with MessageSummary are included in the view MessageEntire by inheritance.




Finally, from your REST controller you can choose the required view by the response. For example, in our case, when we construct a new message, it doesn't have sense to return the likes fields because always is equals to zero, otherwise it has sense when the GET method is invoked.



Jackson Power!