Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization fails with Seq members #4

Closed
awalland opened this issue May 14, 2018 · 1 comment
Closed

Serialization fails with Seq members #4

awalland opened this issue May 14, 2018 · 1 comment
Labels

Comments

@awalland
Copy link

awalland commented May 14, 2018

hi!

Serializing an object with Seq members serializes that object as empty list, even when the sequence has items in it:

import io.vavr.API.List
import io.vavr.collection.List
import io.vavr.collection.Seq
import io.vavr.gson.VavrGson
import org.junit.Test
import kotlin.test.assertEquals

class HelloTest {
    private val expected: String = "{\"ints\":[1,2,3]}"

    data class DataWithSeq(val ints: Seq<Int>)
    data class DataWithList(val ints: List<Int>)

    @Test
    fun testWithSeq() { // <- fails
        val data = DataWithSeq(List(1, 2, 3))
        assertEquals(expected, toJson(data))
    }

    @Test
    fun testWithList() {
        val data = DataWithList(List(1, 2, 3))
        assertEquals(expected, toJson(data))
    }

    private fun toJson(any: Any): String {
        val builder = GsonBuilder()
        VavrGson.registerAll(builder)
        return builder.create().toJson(any)
    }
}

testWithSeq fails with

org.junit.ComparisonFailure: 
Expected :{"ints":[1,2,3]}
Actual   :{"ints":{}}

i only tested it in kotlin not in java but since Seq seems not to be among the registered factories in Gson.factories it is probably not different there.

tested with

        <dependency>
            <groupId>io.vavr</groupId>
            <artifactId>vavr</artifactId>
            <version>0.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.vavr</groupId>
            <artifactId>vavr-gson</artifactId>
            <version>0.9.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.3.1</version>
        </dependency>
ruslansennov added a commit that referenced this issue May 16, 2018
interfaces binding -- fixes #4
@awalland
Copy link
Author

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants