-
Notifications
You must be signed in to change notification settings - Fork 22
Question: Expected a map got 'struct' #38
Comments
Could you please provide the structure definition as well? Are these struct types exported? |
Here is the type structure type Source struct {
Id string `mapstructure:"id"`
Type int `mapstructure:"type"`
}
type DataSourceColumn struct {
Name string `mapstructure:"name"`
Type string `mapstructure:"type"`
}
type DataSource struct {
Id string `mapstructure:"id"`
Name string `mapstructure:"name"`
Description string `mapstructure:"description"`
Tags []string `mapstructure:"tags"`
Source Source `mapstructure:"source"`
Columns []DataSourceColumn `mapstructure:"columns"`
Owner string `mapstructure:"owner"`
Deleted bool `mapstructure:"deleted"`
} Here is the struct I inserted using the new DataSource{
Id: "3389e87e-4a5f-4766-aa56-56d3693331af",
Name: "Business",
Description: "Business Data",
Tags: []string{"Business", "Data"},
Source: Source{
Id: "business_tbl",
Type: Public,
},
Columns: []DataSourceColumn{DataSourceColumn{
Name: "name",
Type: "string",
}},
Owner: "",
Deleted: false,
} Insert went fine, when doing a simple query like |
Thanks! I just realized, there the problem is. I'll fix it soon. |
@dennwc Awesome! Let me know if I can help in anyway. |
@dennwc seems to work nicely :) again thank you. |
@dennwc I have another case of this happening. Here is the model type ItemA struct {
Id string `mapstructure:"id"`
Items []ItemB `mapstructure:"items"`
}
type ItemB struct {
Parent string `mapstructure:"parent"`
Value string `mapstructure:"value"`
} Query:
If I run that in orient, i get the results and items is filled in with array of values from the ItemB class, but when I run this in Go, I get the error:
Question is, does this type of serialization only work if the slice of objects is inserted into the same class? Obviously I am using let so they are not in the same class. |
@josebalius Could you please post a serialized version of result for me, so I can use it in serialization test directly? Here is the example: var docs []orient.Document
err := results.All(&docs)
data, _ := docs[0].Content()
out := base64.StdEncoding.EncodeToString(data) |
@dennwc Running into some errors, here is the code and logs var docs []orient.Document
err := q.All(&docs)
if err != nil {
panic(err)
}
log.Printf("%+v", docs[0])
data, _ := docs[0].Content()
out := base64.StdEncoding.EncodeToString(data)
log.Println(out) Logs:
|
Returned Document seems to be empty. Maybe there are some other documents in the set? In previous case the error was about some type conversion, so it definitely found "items" field at least for one result. |
That's the problem, I know some results are being returned, if I run it in orient, its fine, this is the query with |
"All" will not touch the result if the destination is document, or a slice of documents, so it's not the cause. |
So after bypassing the issues talked about on #29 and #37 I stopped using a custom type (for now) and was able to insert the struct without a problem, yay!
Now, I am trying to get it out, keep getting this error:
The struct has a field called "columns" that holds a slice of "column" structs, and "source" is a struct as well. My question is how can I get it to be okay with it being a struct? Or does this mean that I should convert the whole struct to a map before inserting so that I can then pull it out later and do whatever conversions I need?
What I'm I doing wrong? Tried looking at the mapstructure documentation but couldn't find much.
The text was updated successfully, but these errors were encountered: