Quantcast
Channel: Mkyong.com
Browsing latest articles
Browse All 28 View Live

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.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


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

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

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


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

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

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


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 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
Browsing latest articles
Browse All 28 View Live