This is an automated email from the ASF dual-hosted git repository. kriskras99 pushed a commit to branch serde_ub in repository https://gitbox.apache.org/repos/asf/avro-rs.git
commit deed225c03926e4c1b2a521bf9959d40a9ac6ecc Author: Kriskras99 <[email protected]> AuthorDate: Thu Dec 4 15:14:10 2025 +0100 test: Different field order between Serde and the Schema --- avro/src/ser_schema.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/avro/src/ser_schema.rs b/avro/src/ser_schema.rs index 5a91eb6..93fef0b 100644 --- a/avro/src/ser_schema.rs +++ b/avro/src/ser_schema.rs @@ -1740,13 +1740,11 @@ impl<'a, 's, W: Write> ser::Serializer for &'a mut SchemaAwareWriteSerializer<'s #[cfg(test)] mod tests { use super::*; - use crate::{ - Days, Duration, Millis, Months, decimal::Decimal, error::Details, schema::ResolvedSchema, - }; + use crate::{Days, Duration, Millis, Months, decimal::Decimal, error::Details, schema::ResolvedSchema, Writer, Reader, from_value}; use apache_avro_test_helper::TestResult; use bigdecimal::BigDecimal; use num_bigint::{BigInt, Sign}; - use serde::Serialize; + use serde::{Deserialize, Serialize}; use serde_bytes::{ByteArray, Bytes}; use std::{ collections::{BTreeMap, HashMap}, @@ -2900,4 +2898,49 @@ mod tests { string_record.serialize(&mut serializer)?; Ok(()) } + + + #[test] + fn different_field_order_serde_vs_schema() -> TestResult { + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] + struct Foo { + a: String, + b: String, + } + let schema = Schema::parse_str( + r#" + { + "type":"record", + "name":"Foo", + "fields": [ + { + "name":"b", + "type":"string" + }, + { + "name":"a", + "type":"string" + } + ] + } + "#, + )?; + + + let mut writer = Writer::new(&schema, Vec::new())?; + if let Err(e) = writer.append_ser(Foo { + a: "Hello".into(), + b: "World".into(), + }) { + panic!("{e:?}"); + } + let encoded = writer.into_inner()?; + let mut reader = Reader::with_schema(&schema, &encoded[..])?; + let decoded = from_value::<Foo>(&reader.next().unwrap()?)?; + assert_eq!(decoded, Foo { + a: "Hello".into(), + b: "World".into(), + }); + Ok(()) + } }
