BAEL-2147 Kotlin Data Class from Json using GSON (#5220)

* BAEL-1846: Java Image to Base64 String

* Move from using main method to Junit test

* Update to use environment variables for testing

* reformat and add test file

* spring boot jsp security taglibs

* add more test

* add more test

* refactor spring config

* refactor spring config

* Update README.md

* fi alignment

* fix requested comments

* additional tests and content

* additional tests and content

* update examples

* Delete Readme file

* edit form example

* adding example for spring boot security tag libs

* Remove old tag libs module

* BAEL-2147 Add GsonTest

* BAEL-2147 Remove unused import
This commit is contained in:
Hai Nguyen 2018-09-17 00:02:36 +08:00 committed by maibin
parent 41b2495dcc
commit 9108183846
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package com.baeldung.kotlin.gson
import com.google.gson.Gson
import org.junit.Assert
import org.junit.Test
class GsonUnitTest {
var gson = Gson()
@Test
fun givenObject_thenGetJSONString() {
var jsonString = gson.toJson(TestModel(1,"Test"))
Assert.assertEquals(jsonString, "{\"id\":1,\"description\":\"Test\"}")
}
@Test
fun givenJSONString_thenGetObject() {
var jsonString = "{\"id\":1,\"description\":\"Test\"}";
var testModel = gson.fromJson(jsonString, TestModel::class.java)
Assert.assertEquals(testModel.id, 1)
Assert.assertEquals(testModel.description, "Test")
}
data class TestModel(
val id: Int,
val description: String
)
}