Spring Boot REST: Internationalization (i18n) Example
Learn to add internationalization (i18n) support to Spring Boot REST APIs through the auto-configuration of MessageSource and translation files.
Learn to add internationalization (i18n) support to Spring Boot REST APIs through the auto-configuration of MessageSource and translation files.
Learn to enable HTTP response gzip compression in a Spring Boot application. By default, the gzip compression is disabled in Spring Boot.
In Spring Boot, Jackson is the preferred and default library for JSON serialization and deserialization for REST API requests and responses.
Learn to write unit tests and integration tests in spring boot applications along with spring context, test annotations and mock support.
Spring boot @MockBean annotation used to add mocks to a Spring ApplicationContext. In this tutorial, we will learn the different ways to use this annotation.
Learn to rebuild local repository by deleting all corrupt jars from repository and fix missing maven dependencies problem or force update a maven project.
Learn to unit test Spring Boot webflux controller using @WebFluxTest and WebTestClient, which is used to test reactive endpoints with JUnit.
Learn to write integration tests for given Spring rest controller apis using @SpringBootTest and Junit 5. This technique can be applied to spring boot as well as spring mvc applications, both.
Learn to unit test given Spring rest controller APIs using Junit 5 and mockito. This technique can be applied to spring boot as well as spring MVC applications, both.
The @SpringBootTest annotation in Spring Boot allows us to create integration tests by loading the entire application context. It acts as a bridge between the application configuration and the test framework so that tests can verify the behavior of your application in an environment similar to production.
Learn to create and import test configurations in spring boot applications with the help of @TestConfiguration annotation.
Learn to include JUnit 5 in a Spring boot application and write unit tests. Check out a demo of JUnit 5 tests for Spring Boot REST controller.
Learn to configure timeouts in android apps using retrofit 2 and OkHttp library. We will learn to configure default timeouts and custom connection timeouts in this tutorial.
In this Retrofit2 tutorial, we will learn to parse RSS feeds in an Android application using Retrofit2 and the SimpleXmlConverterFactory.
Learn to parse a sitemap in an Android app using Retrofit2, which uses XML parsing with a simple XML converter dependency. Here’s a Retrofit sitemap reader example.
Learn to execute synchronous and asynchronous calls (i.e. blocking and non-blocking calls) in an android app using Retrofit 2 and OkHttp library.
Though we can easily create Retrofit instances on demand for different client in place, having a dedicated factory method or service generator method is definitely desirable. In this service generator, we can have centralized place to add/modify the authentication, logging and error handling logic. 1. Retrofit service generator A service …
Learn to add logging support in Retrofit 2 using HttpLoggingInterceptor and OkHttpClient APIs. In Retrofit 2, all network operations are performed via OkHttp library. OkHttp provides HttpLoggingInterceptor which logs HTTP request and response data. An example to add HttpLoggingInterceptor to OkHttpClient. 1. Dependency 2. Create and add HttpLoggingInterceptor we can …
Retrofit.Builder class uses the Builder API to allow defining the URL end point for the HTTP operations and finally build a new Retrofit instance.
Learn to perform requests with single, multiple and even optional query parameters and path parameters using @Query and @Path annotations in Retrofit 2.
In this Retrofit 2 tutorial, we will learn the basics of Retrofit and then we will create a declarative REST client for Android for executing HTTP requests against a REST API. 1. What is Retrofit? Retrofit was developed by Square and in its documentation, it is a type-safe REST client …
Learn to configure Google Gson with Spring Boot 2 and 3 applications as the preferred JSON mapper. By default, Spring Boot uses Jackson.
Learn to use custom serialization and deserialization using two interfaces Gson JsonSerializer and JsonDeserializer to convert between json and java object.
Gson JsonParser is used to parse Json data into a parse tree of JsonElement and thus JsonObject, which can be used to get JSON values using their keys.
Gson allows us to exclude or ignore the fields from Java classes using @Expose annotation, exclude fields with modifiers and custom exclusion strategies.
In Gson, multiple versions of the same object can be maintained by using @Since annotation. It takes single parameter – ignoreVersionsAfter.
Learn to work with Gson JsonReader class which is a pull-based streaming JSON parser. It helps in reading a JSON as a stream of tokens. 1. JsonReader Read More : Streaming parser of XML 2. Tokens In streaming mode, every JSON data is considered an individual token. When we use …
All modern applications generally fetch data from remote services (e.g. REST or SOAP) that are mostly either XML or JSON format. Gson helps applications in Java-JSON serialization and deserialization automatically as well as manually, if needed, using simple toJson() and fromJson() methods. 1. Maven Refer to the latest version of …
The default behavior in Gson is that null fields are ignored. For example, if in Employee object, we do not specify the email (i.e. email is null) then the email will not be part of serialized JSON output. Gson ignores null fields because this behavior allows a more compact JSON …
By default, Gson prints the JSON in a compact format. It means there will not be any whitespace in between field names and their value, object fields, and objects within arrays in the JSON output etc. 1. GsonBuilder.setPrettyPrinting() To enable the Gson Pretty Print feature, we must configure the Gson …
To customize the behavior of Gson, use GsonBuilder to create a new customized Gson instance. e.g. pretty printing, FieldNamingPolicy, ExclusionStrategy etc.
Gson @SerializedName is used to change the name of fields between JSON and Java objects while the serialization and deserialization process.
Learn to use Google GSON library to deserialize or parse JSON to Set (e.g. HashSet) in java. Also, learn to serialize Set to JSON.
Learn to use Google GSON library to deserialize or parse a JSON array to a Java array or List object. It’s worth mentioning that JSON has only array datatype. Java has both – arrays and lists. 1. Parsing JSON Array as Root To parse JSON, with array as root, we …
Learn what is UUID and it’s versions and variants. Learn to generate UUID in Java using UUID.randomUUID() API. Also learn to generate version 5 UUID in Java. 1. What is UUID? UUID (Universally Unique IDentifier), also known as GUID (Globally Unique IDentifier) is 128 bits long identifier that is unique …
Learn to work with key value pairs in Java using Pair classes e.g. javafx.util.Pair, ImmutablePair, MmutablePair (common langs) and io.vavr.Tuple2 class. Read More : Tuples in Java 1. Why we need pairs? A pair provide a convenient way of associating a simple key to value. In Java, maps are used …
Learn to read a file from the ‘/resources’ folder in a Spring boot application using ClassPathResource, ResourceLoader interfaces and @Value.
At a high level, @RestController is a convenient annotation for writing REST APIs and combines @Controller and @ResponseBody annotations.
To disable the spring boot banner logo from the console or log files, we can make changes in 3 possible ways i.e. programmatically, properties, or startup arguments. 1. Disable Banner Programmatically Set banner mode in the program using setBannerMode(Banner.Mode.OFF) method call which starts the application. 2. Disable Banner using Properties …
Learn about some frequently used spring boot annotations as well as which work behind the scene. e.g. @SpringBootApplication and @EnableAutoConfiguration.
Learn to convert a string to date time instance classes e.g. ZonedDateTime or OffsetDateTime classes, using DateTimeFormatter class in Java. 1. Instant, OffsetDateTime and ZonedDateTime Classes In Java 8, OffsetDateTime and ZonedDateTime – both store an instant on the universal timeline to nanosecond precision. OffsetDateTime adds to the instant the …
Learn to parse date and time strings into instances of LocalDate and LocalDateTime using strict style using ResolverStyle.STRICT parameter with DateTimeFormatter instance.
Spring boot supports separate logging configurations for separate and multiple runtime environments or spring profiles. Learn with example.
Learn to use and configure logging to console in spring boot application. Also learn to configure and use console appenders available in logback and log4j2.
Learn to create multiple log files in spring boot applications using multiple file appenders. Learn to configure the appenders wiih log4j2 and logback.
Project lombok can also be used to configure logging in spring boot applications and thus removing the boilerplate code for getting the logger instance.
Logging in spring boot is very easy to configure. Learn to support the logging providers such as commons logback, log4j2 and commons logging in Spring boot.
Learn to check if a string is palindrome string with simple java programs using stack, queue, for and while loops. A palindrome is equal to its reverse.
Learn to write a java program to remove all the white spaces from a given string using regular expression (“\\s”) and isWhitespace() method.
Learn to create aspectj based interceptor in spring boot application to write performance logging based on time taken in method executions with example.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.