Kotlin – Convert Object to/from JSON with Jackson 2.x

This tutorial shows you how to use Jackson 2.x to convert Kotlin object to/from JSON.

Related Post: Kotlin List & Mutable List tutorial with examples

>>> Refer to: JavaSampleApproach.com

I. Technology

– Java 1.8
– Kotlin 1.1.2
– Maven 3.5.1

II. Overview

1. Goal

Convert JSON string/JSON file/JSON url to Person(name:String,age:Int,messages:List) Kotlin Object, then convert Person object to JSON string/JSON file.

2. Steps to do

– add Dependency:

– import com.fasterxml.jackson.module.kotlin.*
– use ObjectMapper instance:

III. Practice

0. Person Class

1. Json String/URL/File to Object

Check Result:

2. Object to Json String/File

Check Result:

IV. More Practice

1. Json array format to List


2. Json to Map


Add Comment