Giter Site home page Giter Site logo

vavr-gson's People

Contributors

mfashby avatar mincong-h avatar ruslansennov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vavr-gson's Issues

Serialization fails with Seq members

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>

Add TypeHierarchyAdapters?

When a class contains a field with a vavr interface type, e.g. Map, Gson can't deserialize it, as it needs a certain implementation of Map. Often a particular implementation (like HashMap) would be a good default for the majority of classes, so one could just register a TypeHierarchyAdapter using a HashMap to deserialize a Map field. Such TypeHierarchyAdapters could be part of the library (but not registered in VavrGson, just as additional helpers).

Project setup

Hi @before,

great to have you onboard :)

In a first step we should setup the javaslang-gson repository first an initial commit.

You may take the javaslang-jackson project as template. It is a Maven layout. Or you may choose Gradle for the build - your call.

Please ask on any questions - I will assist you whenever possible.

Greets

- Daniel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.