-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Deserializing a String field inside a flattende struct fails if the field contains a valid integer #344
Comments
This does indeed look like a bug. I don't know when I'll have time to look into it, so patches are welcome if you can find a fix yourself. I'll note that the presence of |
It seems like |
I don't know. I don't know much about serde internals. I do know that the I won't have time to look into this any time soon I'm afraid. |
Yeah, it seems to be unsupported in That's unfortunate :/ |
I believe the issue here is that CSV is not actually a "self-describing" format, and therefore should not support
As far as I can tell, there's no way to actually fix this without fundamentally changing the csv format to be actually self-describing. IMO there shouldn't be a See also: serde.rs's documentation for using |
@Anders429 That is a very insightful comment, thank you. I don't think I realized myself at all that flatten support depended on |
It's definitely surprising, because you could easily implement most Seems like flattening is hard to support for |
I ran into the exact same issue today, here's my code: #[derive(Debug, serde::Deserialize)]
#[serde(rename_all(deserialize = "PascalCase"))]
pub struct PartMappingRecord {
eda: CSVEdaToolValue,
manufacturer: String,
mpn: String,
#[serde(flatten)]
fields: HashMap<String, String>,
} the csv file:
the error:
In the above example, the "Mpn" column's value is ok, but the "Name" column, which is flattened into the source: For my use-case, I need to support any number of arbitrarily named csv columns, since each different EDA tool that generates placement CSV files will always have their own column names and the part mappings file has to use the same column names too. Additionally, the 'line' counter seems to be 0 based, which is confusing to humans, since most text editors and IDEs display line numbers starting from 1, for example: Suggestions on workarounds or solutions greatly appreciated! |
I think something folks sometimes forget is that serde is an optional convenience feature. You don't actually need to use it! You can use |
It's not. Or it's not intended to be: https://docs.rs/csv/latest/csv/struct.Position.html#method.line If you are experiencing the opposite, please open a new issue with an MRE. |
My project uses serde with serde-derive for other serialization tasks so it made sense to use it for CSV files too. I'm just about to start investigating a solution/work-around to this issue and will keep that in mind. thanks for the timely reminder!
ok, I will check again and future errors and will open issues as required. |
* 'flatten' doesn't work if one of the fields contains only integers. * See BurntSushi/rust-csv#344 (comment) Example CSV file that causes an issue is as follows: ``` "Eda","Manufacturer","Mpn","Name","Value" "DipTrace","Molex","0479480001","0479480001","" ```
What version of the
csv
crate are you using?1.3.0
Briefly describe the question, bug or feature request.
When deserializing to a
String
field using serde,csv
can handle a field containing123
.However, when doing the same to a flattened field,
csv
can no longer deserialize123
to theString
field and I get the error:Include a complete program demonstrating a problem.
What is the observed behavior of the code above?
Output:
What is the expected or desired behavior of the code above?
Output:
The text was updated successfully, but these errors were encountered: