Kotlin – Convert Object to/from JSON with Gson

This tutorial shows you how to use Gson to convert Kotlin object to/from JSON.

>>> 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 to Person(name:String,age:Int,messages:List) Kotlin Object/List/Map
– Convert Person Object/List/Map to JSON string.

2. Steps to do

– add Dependency:

– import:

– use Gson instance:

III. Practice

0. Person Class

1. Object
1.1 from JSON

Check Result:

1.2 to JSON

Check Result:

2. List

Check Result:

3. Map

Check Result:

2 thoughts on “Kotlin – Convert Object to/from JSON with Gson

    1. Hi Kames,

      Because we don’t indicate path for person.json file, so you should put it in the root folder of the Maven Project (the folder pom.xml is located in) 🙂

      Best Regards!

Add Comment