json - How best to send complex data with FCM / GCM using Go -


both fcm , gcm documentation give structure of data payload map[string]string (although google's gcm package implements @ map[string]interface{})

however, there many cases simple flat key:value structure doesn't meet needs of application. examples when slice of values needed, or when non-trivial struct needs sent.

what cleanest way of sending more complicated data structures map[string]string?


conclusion: have marked answer fl0cke correct given provides solution sending complex data fcm / gcm using go. however, clear fcm documentation, intention data key:value string pairs moving forward, , sure nothing gets broken in future, sticking simple key:value string pairs.

according this answer, possible send nested data fcm/gcm. that, can write own fcm client or fork google's implementation , change type definition of data from

type data map[string]interface{} 

to

type data interface{} 

and plug in type json serializable (e.g. nested structs).


it possible send data via json string without changing type definition of data:

// first marshal complex data structure complexdata := somecomplexstruct{...} b, _ := json.marshal(complexdata)  // assign returned json string 1 key of choice data := map[string]interface{}{"key":string(b)} 

you have unquote json string before parsing on client.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -