https://kotlinlang.org logo
#klaxon
Title
# klaxon
c

cedric

03/07/2018, 9:10 PM
@nikbucher Fixed in 2.1.10.
🚀 1
n

nikbucher

03/07/2018, 9:14 PM
I tried to add this by myself but I stuck at Klaxon line 215 🙂
c

cedric

03/07/2018, 9:15 PM
You were in the right place, and that change allowed me to fix a potential bug in Klaxon, so thanks!
n

nikbucher

03/07/2018, 9:18 PM
You're welcome
btw: I changed the first two tests to
Copy code
package com.beust.klaxon

import org.testng.Assert
import org.testng.annotations.Test

@Test
class JsonAnnotationTest {
    private val jsonString: String = json { obj(
            "name" to "John",
            "change" to 1
    ) }.toJsonString()

    fun ignoredWithAnnotation() {
        class IgnoredWithAnnotation(
                val name: String,
                @Json(ignored = true)
                val change: Int = 0)

        val result = Klaxon().parse<IgnoredWithAnnotation>(jsonString)
        Assert.assertEquals(result?.name, "John")
        Assert.assertEquals(result?.change, 0)
    }

    fun ignoredWithPrivate() {
        class IgnoredWithPrivate(
                val name: String,
                private val change: Int = 0){
            fun changed(): Boolean = change != 0
        }

        val result = Klaxon().parse<IgnoredWithPrivate>(jsonString)
        Assert.assertEquals(result?.name, "John")
        Assert.assertEquals(result?.changed(), false)
    }

    fun overrideIgnoredWithPrivateByAnnotation() {
        class OverrideIgnoredWithPrivate(
                val name: String,
                @Json(ignored = false)
                private val change: Int = 0){
            fun changed(): Boolean = change != 0
        }

        val result = Klaxon().parse<OverrideIgnoredWithPrivate>(jsonString)
        Assert.assertEquals(result?.name, "John")
        Assert.assertEquals(result?.changed(), true)
    }
}
because they don't fail, if you remove @Json(ignored = true) or private
c

cedric

03/07/2018, 9:22 PM
Ah good catch, can you send a PR? (also, pull first, I just moved the new test to that file)
n

nikbucher

03/07/2018, 9:25 PM
ok
should I add the overrideIgnoredWithPrivateByAnnotation method too?
3 Views