File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -187,4 +187,38 @@ mod tests {
187
187
}
188
188
) ;
189
189
}
190
+
191
+ #[ test]
192
+ fn deserialize_new_fields_in_the_middle ( ) {
193
+ // fields can be added, but only to the end of the struct
194
+
195
+ #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
196
+ struct TestV1 {
197
+ a : String ,
198
+ b : u32 ,
199
+ }
200
+
201
+ #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
202
+ struct TestV2 {
203
+ a : String ,
204
+ #[ serde( default ) ]
205
+ c : u8 ,
206
+ b : u32 ,
207
+ }
208
+
209
+ let v1 = TestV1 {
210
+ a : "foo" . to_string ( ) ,
211
+ b : 999999 ,
212
+ } ;
213
+ let v2: TestV2 = from_msgpack ( to_msgpack_vec ( & v1) . unwrap ( ) ) . unwrap ( ) ;
214
+
215
+ assert_eq ! (
216
+ v2,
217
+ TestV2 {
218
+ a: "foo" . to_string( ) ,
219
+ c: 0 ,
220
+ b: 999999 ,
221
+ }
222
+ ) ;
223
+ }
190
224
}
You can’t perform that action at this time.
0 commit comments