Kotlin – How to convert Object to/from JSON by Gson with Kotlin language

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

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:

By JavaSampleApproach | August 29, 2017.


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*