Quantcast
Channel: Mkyong.com
Browsing index pages (28 articles)
↧

How to traverse all files from a folder in Java

In Java, we can use the Files.walk() API to traverse all files from a folder and its subfolders. Table of contents: 1. Traverse all files from a folder in Java 2. Traverse all files from a folder and...

View Article


Pretty Print JSON with JSON.simple

This article shows how to pretty print JSON with JSON.simple. Table of contents: 1. Setup JSON.simple 2. Default Compact Print JSON 3. Pretty Print JSON with JSON.simple 4. Write Pretty Print JSON to a...

View Article


How to exclude fields in Gson

In GSON, we can use the transient keyword, ExclusionStrategy, and @Expose to exclude fields during the JSON serialization or deserialization process. Table of contents: 1. Setup Google Gson 2. Using...

View Article

Gson supports Java 8 date time types

Gson does not directly support Java 8’s date-time APIs like LocalDate, LocalDateTime, and ZonedDateTime. However, we can create a custom JSON serializer to support Java 8 date-time types. This article...

View Article

Gson custom field name with @SerializedName

When the JSON field name doesn’t exactly match the Java object field names, we can use @SerializedName to change the JSON’s matching field name in Gson. Table of contents: 1. Setup Google Gson 2. JSON...

View Article


Read and Write JSON to File using Gson

This article shows how to use Gson to write a Java object to a JSON file and read that JSON file back into a Java object. Table of contents: 1. Download Google Gson 2. A Java Object 3. Write Java...

View Article

Jackson Custom Serializer and Deserializer Examples

This article shows how to create a Jackson custom serializer and deserializer to parse JSON data that contains a LocalDate type. The Jackson custom serializer or deserializer is useful when we want to...

View Article

Jackson Custom field name with @JsonProperty

When the JSON field name doesn’t exactly match the Java field names, we can use @JsonProperty to change the name of a JSON field in Jackson. Table of contents: 1. Setup Jackson 2. JSON Unrecognized...

View Article


Moshi java.time.LocalDate requires explicit JsonAdapter to be registered

Moshi does not have built-in adapters to process types like Java 8 date time APIs java.time.* or JSR-310; we need to manually provide a custom adapter to handle the Java 8 date time type. This article...

View Article


How to pretty print JSON using Moshi

This article shows how to use Moshi’s JsonAdaptor indent method to enable the pretty print JSON. Table of contents: 1. Download Moshi 2. Compact print JSON (Default) 3. Pretty print JSON using Moshi 4....

View Article

Moshi – java.math.BigDecimal requires explicit JsonAdapter to be registered

Moshi does not have built-in adapters to process types like java.math.BigDecimal; we need to manually provide a custom adapter to handle the BigDecimal type. Table of contents: 1. Download Moshi 2....

View Article

How to write JSON to a file using Moshi

This article shows how to write JSON to a file using Moshi. Table of contents: 1. Download Moshi 2. Write JSON to a file using Moshi 3. Read JSON from a file using Moshi 4. Download Source Code 6....

View Article

How to parse JSON using Moshi

This article shows how to parse JSON using Moshi. Table of contents: 1. Download Moshi 2. Parse JSON using Moshi 3. Parse JSON Array using Moshi 4. Convert Java Object to JSON String 5. Download Source...

View Article


Jackson and Lombok examples

This article shows how to use Jackson and Lombok together. Table of contents: 1. Download Jackson and Lombok 2. Model with Lombok annotations 3. Parse JSON using Jackson 5. Download Source Code 6....

View Article

How to map a subset of a JSON file using Jackson

This article shows how to map a subset of a JSON file using Jackson. Table of contents: 1. Download Jackson 2. Map a subset of a JSON file 3. Define Java Classes that reflect JSON structure 4. Ignoring...

View Article


Write JSON to a file with Jackson

This article shows you write JSON to a file with Jackson. Table of contents: 1. Download Jackson 2. Define a Java Object 3. Write JSON to a File 4. Download Source Code 5. References P.S Tested with...

View Article

Convert Java Objects to JSON with Jackson

This article will show you how to convert Java objects to JSON with Jackson. Table of contents: 1. Setup Jackson 2. Jackson quick examples 3. Convert Java Object to JSON using Jackson 4. Convert JSON...

View Article


How to ignore a field with Jackson

In Jackson, we can use @JsonIgnore to ignore a single field, @JsonIgnoreProperties to ignore multiple fields and @JsonIgnoreType to ignore a specified type during JSON serialization and...

View Article

How to Run a CommandLineRunner Bean Conditionally in Spring Boot

This article shows different ways to run a CommandLineRunner bean conditionally in a Spring Boot application. Table of contents: 1. Using @ConditionalOnProperty 2. Using Environment 3. Using Spring...

View Article

Spring Boot CommandLineRunner Example

This article tells what is CommandLineRunner and different ways of implementing it or use it in Spring Boot. Table of contents: 1. What is CommandLineRunner? 2. Implementing CommandLineRunner 3. @Bean...

View Article
Browsing index pages (28 articles)


Latest Images