marcinosypka opened a new issue, #3049:
URL: https://github.com/apache/fory/issues/3049

   ### Search before asking
   
   - [x] I had searched in the [issues](https://github.com/apache/fory/issues) 
and found no similar issues.
   
   
   ### Version
   
   Tested on arch linux  kernel 6.17 with rust stable-x86_64-unknown-linux-gnu 
rustc 1.91.1
   
   Cargo.toml
   ```
   [package]
   name = "fory-tests"
   version = "0.1.0"
   edition = "2024"
   
   [dependencies]
   fory = "0.13.2"
   fory-core = "0.13.2"
   fory-derive = "0.13.2"
   ```
   
   
   
   ### Component(s)
   
   Rust
   
   ### Minimal reproduce step
   
   ```rust
   use std::marker::PhantomData;
   
   use fory::{
       Error, Fory, ForyDefault, ForyObject, ReadContext, Serializer, 
TypeResolver, WriteContext,
   };
   
   #[derive(Debug, PartialEq)]
   struct Wrapper<T> {
       value: String,
       _marker: PhantomData<T>,
   }
   
   impl<T: 'static> Serializer for Wrapper<T> {
       fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), 
Error> {
           context.writer.write_varuint32(self.value.len() as u32);
           context.writer.write_utf8_string(&self.value);
           Ok(())
       }
   
       fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
           let len = context.reader.read_varuint32()? as usize;
           let value = context.reader.read_utf8_string(len)?;
           Ok(Self {
               value,
               _marker: PhantomData,
           })
       }
   
       fn fory_type_id_dyn(&self, type_resolver: &TypeResolver) -> Result<u32, 
Error> {
           Self::fory_get_type_id(type_resolver)
       }
   
       fn as_any(&self) -> &dyn std::any::Any {
           self
       }
   }
   
   impl<T> ForyDefault for Wrapper<T> {
       fn fory_default() -> Self {
           Self {
               value: "".into(),
               _marker: PhantomData,
           }
       }
   }
   
   #[derive(ForyObject, Debug, PartialEq)]
   struct MyStruct {
       my_vec: Vec<Wrapper<Another>>,
   }
   
   #[derive(ForyObject, Debug, PartialEq)]
   struct Another {}
   
   fn main() -> Result<(), Box<dyn std::error::Error>> {
       let mut fory = Fory::default().compatible(true);
       // let mut fory = Fory::default(); // Without compatible it works fine.
       // let mut fory = Fory::default().xlang(true); // Works fine with xlang 
enabled
   
       fory.register::<MyStruct>(1)?;
       fory.register::<Another>(2)?;
       fory.register_serializer::<Wrapper<Another>>(3)?;
   
       let w1 = Wrapper::<Another> {
           value: "Value1".into(),
           _marker: PhantomData,
       };
       let w2 = Wrapper::<Another> {
           value: "Value2".into(),
           _marker: PhantomData,
       };
   
       let ms = MyStruct {
           my_vec: vec![w1, w2],
       };
   
       let bytes = fory.serialize(&ms)?;
       fory.deserialize::<MyStruct>(&bytes)?;
       Ok(())
   }
   
   ```
   
   ### What did you expect to see?
   
   Expected fory to deserialize data properly.
   
   ### What did you see instead?
   
   Error: TypeMismatch(787, 6).
   
   ### Anything Else?
   
   I’m not entirely sure whether I’m handling the implementation of a generic 
serializer for a custom type correctly. I can see that the problem occurs when 
`compatible` is enabled. The code works just fine without `compatible` or when 
`xlang` is enabled. I don’t have any issues serializing just the vector of 
Wrapper; the problem arises when this vector is wrapped inside another struct, 
as shown in the example code.
   
   ### Are you willing to submit a PR?
   
   - [ ] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to