Administrator

Lokesh Gupta

Lokesh Gupta is a Java developer with more than 20 years of experience and the founder of HowToDoInJava, which he started in 2012. He has worked on Java and Spring applications at Hewitt Associates, Hughes Systique, Adobe and Bank of America. The site has over 1,600 tutorials on Java, Spring Boot, Hibernate, testing and TypeScript. Every example is run and verified before it is published, and the source code is on GitHub.

Website: https://howtodoinjava.com

Github: https://github.com/lokeshgupta1981/

Twitter: @HowToDoInJAVA

LinkedIn: https://www.linkedin.com/in/lokeshgupta1981/

My Articles:

Integration Testing with @SpringBootTest and JUnit 5

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.

Spring Boot 3 with JUnit 5

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.

Parsing RSS Feed using Retrofit2

In this Retrofit2 tutorial, we will learn to parse RSS feeds in an Android application using Retrofit2 and the SimpleXmlConverterFactory.

Parsing a Sitemap using Retrofit2

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.

Retrofit 2 Service Generator

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 …

Logging in Retrofit 2

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 …

Guide to Retrofit.Builder API

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.

Retrofit 2 Tutorial: Declarative REST Client for Android

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 …

Use Gson with Spring Boot 4

Use Gson with Spring Boot 4.1.2. Compare an injected Gson bean with MVC JSON responses, customize LocalDate, and select Gson for the message converter.

Gson JsonParser

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 – Exclude or Ignore Fields

Gson allows us to exclude or ignore the fields from Java classes using @Expose annotation, exclude fields with modifiers and custom exclusion strategies.

Gson JsonReader

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 …

Gson Tutorial: Java JSON toJson and fromJson Examples

Learn Gson with examples. Convert Java objects, lists and maps to JSON and back with toJson() and fromJson(), configure GsonBuilder, use @SerializedName and @Expose, read JSON with JsonParser and write a custom TypeAdapter.

Gson – Serialize Null Values

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 …

Gson – Pretty Print 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 …

Gson – Parse JSON Array to Java Array or List

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 …

Disable the Spring Boot Startup Banner

Turn off the Spring Boot startup banner with properties, a launch argument, or SpringApplication. See verified Spring Boot 4.1.2 output and how overrides work.

Parse a String to UTC Date Time in Java (Z, Offset, GMT)

Learn to parse a date-time string to UTC in Java with Instant, OffsetDateTime and ZonedDateTime. Covers strings with Z, an offset, GMT or no zone at all. Also covers RFC 1123 dates, old SimpleDateFormat code and common DateTimeParseException causes.

Spring Boot Console Logging

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.

Spring Boot Logging with Lombok

Project lombok can also be used to configure logging in spring boot applications and thus removing the boilerplate code for getting the logger instance.

Spring Boot and Ehcache 3 Example

Learn to configure Ehcahce 3 with Spring Boot 2.x and Spring Boot 3.x applications, use @Cacheable annotation and log caching events.a

Spring WebMVC Optional @PathVariable

Learn to have optional @PathVariable valuein spring mvc application when required attribute to set to false or expect variable’s value to null.

About Us

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.