dbase-rs
dbase-rs copied to clipboard
Problem with deserialising numeric field after character field
I found that when I try to use the serde feature to deserialize a record which contains both character and numeric fields the numeric field (f64) deserialization fails with the error below. I am able to read to a dbase::Record
no problem and it comes back with a character and a numeric field.
Error { record_num: 0, field: Some(FieldInfo { name: "FID_rail_d", field_type: Numeric, displacement_field: [0, 0, 0, 0], field_length: 9, num_decimal_places: 0, flags: FieldFlags(0), autoincrement_next_val: [0, 0, 0, 0, 0], autoincrement_step: 0 }), kind: BadConversion(FieldTypeNotAsExpected { expected: Character, actual: Numeric }) }'
#[derive(Debug, Serialize, Deserialize)]
struct R {
#[serde(rename = "ISO")]
iso: String,
#[serde(rename = "FID_countr")]
fid_countr: f64,
}
I tried creating a minimal reproducable example by serializing this and then deserializing, but this problem didn't occur, so I wonder if it might be something perculiar about the layout of the dbf file I'm reading.
I'm using through shapefile version 0.3, so that's dbase 0.2, but I've also reproduced with dbase 0.3.
To reproduce, obtain the dbf from the shapefile at : https://biogeo.ucdavis.edu/data/diva/rrd/ALB_rrd.zip
use std::io::Cursor;
use serde::*;
use dbase::*;
#[derive(Debug, Serialize, Deserialize)]
struct R {
#[serde(rename = "ISO")]
iso: String,
#[serde(rename = "FID_countr")]
fid_countr: f64,
}
#[test]
fn test() {
let mut reader = dbase::Reader::from_path("ALB_rrd/ALB_rails.dbf").unwrap();
let stations = reader.read_as::<R>().unwrap();
}