firebase / firebase/firebase-admin-go
Way to unmarshal `Message` from json string (apns.payload.aps.*)
- Dominant language
- Go
- Stars
- 1.3k
- Forks
- 274
- Avg merge
- 10h 39m
- Merged PRs (30d)
- 2
Description
### [REQUIRED] Step 2: Describe your environment
* Operating System version: macOS Ventura 13.5.2
* Firebase SDK version: 4.12.1
* Library version: ?
* Firebase Product: messaging (auth, database, storage, etc)
### [REQUIRED] Step 3: Describe the problem
#### Steps to reproduce:
I've deal with json like:
```json
{
"token": "$FCM_TOKEN",
"data": {
"title": "data.title",
"body": "data.body"
},
"notification": {
"title": "notification.title",
"body": "notification.body"
},
"apns": {
"payload": {
"aps": {
"content-available": false,
"sound": "1",
"mutable-content": true,
"alert": {
"title": "apns.payload.aps.alert.title",
"subtitle": "apns.payload.aps.alert.subtitle",
"body": "apns.payload.aps.alert.body"
}
}
}
}
}
```
For use `Message`'s interface, I have to unmarshal this json to `Message` struct.
So I tried to:
```go
// 1st way
message := &messaging.Message{}
err = message.UnmarshalJSON(messageJsonString)
if err != nil {
fmt.Println(err.Error())
}
// 1st way's error:
json: cannot unmarshal bool into Go struct field APNSConfig.apns.payload of type int
```
```go
// 2nd way
message := &messaging.Message{}
err = json.Unmarshal(messageJsonString)
if err != nil {
fmt.Println(err.Error())
}
// 2nd way's error:
json: cannot unmarshal bool into Go struct field APNSConfig.apns.payload of type int
```
I did some testing and found that it works fine without "content-available" and "mutable-content" in the json.
How can I parse content-available and mutable-content?
This fields are from [apple reference](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943360)
Contributor guide
Research direction
Start by locating messaging.Message, its UnmarshalJSON method, and the APNSConfig.apns.payload field mentioned in the error. Reproduce the failure with the supplied JSON and inspect how content-available and mutable-content are represented. Done means the Message JSON unmarshals successfully while preserving those APNs fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100