slatekit / kiit

Kotlin Framework for Apps, APIs, CLIs, Jobs, Mobile and more...
https://www.kiit.dev
Apache License 2.0
112 stars 13 forks source link

Result: Minor improvements for serialization #316

Closed kishorereddy closed 3 years ago

kishorereddy commented 3 years ago

Overview

Encode/Decode the Result type to/from JSON. This is used for the API responses. Also, this changes supports decoding of errors in the response back to Outcome.

Ticket(s)

n/a

Links(s)

n/a

Dependencies

n/a

Design

The sample response below will be correctly decoded to an Outcome with a list of Err values.

{
                "success": false,
                "name": "CONFLICT",
                "type": "Errored",
                "code": 500004,
                "desc": "Conflict",
                "value": null,
                "meta": null,
                "tag": null,
                "errs": [
                    {
                        "field": "email",
                        "type": "input",
                        "message": "Email already exists",
                        "value": "slate.kit@gmail.com"
                    },
                    {
                        "field": "",
                        "type": "action",
                        "message": "Unable to register user",
                        "value": ""
                    }
                ]
            }

Notes

n/a

Pending

n/a

Tests

Added unit-tests