Showing posts with label REST. Show all posts
Showing posts with label REST. Show all posts
Monday, February 1, 2016

Java: Convert JSON to DTO Object

Use Jakson

U can convert JSON to DTO and back automatically with ObjectMapper:
  • Convert Java object to JSON, writeValue(...)
  • Convert JSON to Java object, readValue(...)
  • Convert JSON to List of Java objects, readValues(...)
U can use field with different name with @JsonProperty(...) annotation.
U can skip unneeded properties with the following method: configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

Java: Authenticate via HttpClient 4

It's often might be needed to get/post some info from the third party sites via HTTP. But, most of the times you have to be signed into that web-resources.
Friday, January 29, 2016

Check HTTP Response Status for Success

All HTTP 2xx mean successful status codes.
So, it's fairly easy to check, but a bit harder to not duplicate those checks everywhere:)
Tuesday, January 19, 2016

Java: Forget About JSP

I hope that you already have forgotten about JSF (JavaServer Faces) :)
Not long time ago, all feeds were overloaded by post about, why everyone has to stop using JSF. However JSP (JavaServer Pages) is usually a kind of pain in ass for developers as well, because it's badly readable, not reusable, different from html syntax, not obvious, coupled, etc.

So, here is a better way, that should be chosen in favour of JSP:

Themeleaf

Thymeleaf is a Java library. It is a template engine capable of processing and generating HTML, XML, JavaScript, CSS and text, and can work both in web and non-web environments. It is better suited for serving the view layer of web applications, but it can process files in many formats, even in offline environments.

It provides an optional module for integration with Spring MVC, so that you can use it as a complete substitute of JSP in your applications made with this technology, even with HTML5.
As mentioned above, Thymeleaf is well integrated with Spring and allows more intuitive way to handle views part, which makes it's quite easy usable & useful especially for small fast projects.
Wednesday, July 15, 2015

REST (RESTful Webservices)