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

Empty contens are encoded to null #468

Open
kyu-suke opened this issue Jul 29, 2024 · 1 comment
Open

Empty contens are encoded to null #468

kyu-suke opened this issue Jul 29, 2024 · 1 comment
Assignees
Labels

Comments

@kyu-suke
Copy link

System Informations

  • Go version: go1.22.5 darwin/arm64
  • OS: macOS 14.4.1

Expected Behavior

{
    "type": "flex",
    "contents": {
        "type": "bubble",
        "header": {
            "type": "box",
            "layout": "vertical",
            "contents": []
        },
        "body": {
            "type": "box",
            "layout": "vertical",
            "contents": [
                {
                    "type": "box",
                    "layout": "baseline",
                    "contents": [],
                    "spacing": "sm"
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                        {
                            "type": "box",
                            "layout": "baseline",
                            "contents": [],
                            "spacing": "sm"
                        }
                    ]
                }
            ]
        }
    }
}

{
    "type": "flex",
    "altText": "",
    "contents": {
        "type": "bubble",
        "header": {
            "layout": "vertical",
            "flex": 0,
            "type": "box",
            "contents": []
        },
        "body": {
            "layout": "vertical",
            "flex": 0,
            "type": "box",
            "contents": [
                {
                    "type": "box",
                    "layout": "baseline",
                    "flex": 0,
                    "contents": null,
                    "spacing": "sm"
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "flex": 0,
                    "contents": [
                        {
                            "type": "box",
                            "layout": "baseline",
                            "flex": 0,
                            "contents": [], // is should empty?
                            "spacing": "sm"
                        }
                    ]
                }
            ]
        }
    }
}

Current Behavior

The contents value of type box of flex message contents is encoded to null when it is nested and empty. So narrowcast API returns May not be empty.
I think it is necessary to modify the unmarshal logic in linebot/messaging_api/model_flex_box.go.
If this approach is acceptable, I would like to proceed with submitting a pull request. Please let me know if there are any concerns or suggestions for improvement.

{
    "type": "flex",
    "altText": "",
    "contents": {
        "type": "bubble",
        "header": {
            "layout": "vertical",
            "flex": 0,
            "type": "box",
            "contents": []
        },
        "body": {
            "layout": "vertical",
            "flex": 0,
            "type": "box",
            "contents": [
                {
                    "type": "box",
                    "layout": "baseline",
                    "flex": 0,
                    "contents": null,
                    "spacing": "sm"
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "flex": 0,
                    "contents": [
                        {
                            "type": "box",
                            "layout": "baseline",
                            "flex": 0,
                            "contents": null, // `[]` is encoded to `null`
                            "spacing": "sm"
                        }
                    ]
                }
            ]
        }
    }
}

Steps to Reproduce

flex2 := `{
    "type": "flex",
    "contents": {
        "type": "bubble",
        "header": {
            "type": "box",
            "layout": "vertical",
            "contents": []
        },
        "body": {
            "type": "box",
            "layout": "vertical",
            "contents": [
                {
                    "type": "box",
                    "layout": "baseline",
                    "contents": [],
                    "spacing": "sm"
                },
                {
                    "type": "box",
                    "layout": "vertical",
                    "contents": [
                        {
                            "type": "box",
                            "layout": "baseline",
                            "contents": [],
                            "spacing": "sm"
                        }
                    ]
                }
            ]
        }
    }
}`

f2, err := messaging_api.UnmarshalMessage([]byte(flex2))
if err != nil {
	fmt.Println(err)
}
ff2, _ := json.MarshalIndent(f2, "", "    ")
fmt.Println(string(ff2))
@kyu-suke kyu-suke added the bug label Jul 29, 2024
@habara-k habara-k self-assigned this Jul 30, 2024
@habara-k
Copy link
Contributor

habara-k commented Aug 8, 2024

Thank you for using line-bot-sdk-go.

We appreciate your report. We have also confirmed the behavior on our end. It seems that an empty array is being unmarshaled as null.

We believe this behavior should be corrected. It would be greatly appreciated if you could create a PR to fix this issue. Thank you in advance for your cooperation.

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