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

Uniform pattern for lambda input/output serialize #195

Open
hidden-dimensions opened this issue Jan 29, 2018 · 1 comment
Open

Uniform pattern for lambda input/output serialize #195

hidden-dimensions opened this issue Jan 29, 2018 · 1 comment
Assignees
Labels

Comments

@hidden-dimensions
Copy link

hidden-dimensions commented Jan 29, 2018

Currently skygear lambda function takes either Object[] args or Map<String, Object> as input parameter, and returns JSONObject on LambdaResponseHandler, which make serialization asymmetric (toMap and fromJson).

Suggest to return Map<String,Object> on LambdaResponseHandler.


For kotlin we can expect a uniform serialization like the following:

data class TestData(
        val foo: String,
        val nested: Nested
) {
    data class Nested(
            val nestedInt: Int,
            val nestedString: String
    ) {
        fun toMap() = mapOf(
                "nestedInt" to nestedInt,
                "nestedString" to nestedString
        )
        companion object {
            @Throws(NullPointerException::class, ClassCastException::class)
            fun from(map: Map<*,*>): Nested {
                return Nested(
                        nestedInt = map["nestedInt"] as Int,
                        nestedString = map["nestedString"] as String
                )
            }
        }
    }

    fun toMap() = mapOf(
            "foo" to foo,
            "nested" to nested.toMap()
    )
    companion object {
        @Throws(NullPointerException::class, ClassCastException::class)
        fun from(map: Map<*, *>): TestData {
            return TestData(
                    foo = map["foo"] as String,
                    nested = Nested.from(map["nested"] as Map<*,*>)
            )
        }
    }
}
@carmenlau carmenlau changed the title Uniform pattern for lambda input/output serialize Map<String,Object> support for lamda function Jan 30, 2018
@carmenlau carmenlau changed the title Map<String,Object> support for lamda function Uniform pattern for lambda input/output serialize Jan 31, 2018
@carmenlau
Copy link
Contributor

Since map is not the only result type for lambda, it would be string or array. So need further planning is needed. Will put this issue to backlog first and start planning again if it gets more votes.

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

3 participants