Troubleshooting
This page covers common issues and solutions when using cross-language serialization.
Type Registration Errors
"Type not registered" Error
Symptom:
Error: Type 'example.Person' is not registered
Cause: The type was not registered before deserialization, or the type name doesn't match.
Solution:
-
Ensure the type is registered with the same name on both sides:
// Java
fory.register(Person.class, "example.Person");# Python
fory.register_type(Person, typename="example.Person") -
Check for typos or case differences in type names
-
Register types before any serialization/deserialization calls
"Type ID mismatch" Error
Symptom:
Error: Expected type ID 100, got 101
Cause: Different type IDs used across languages.
Solution: Use consistent type IDs:
// Java
fory.register(Person.class, 100);
fory.register(Address.class, 101);
# Python
fory.register_type(Person, type_id=100)
fory.register_type(Address, type_id=101)
Type Mapping Issues
Integer Overflow
Symptom: Values are truncated or wrapped unexpectedly.
Cause: Using different integer sizes across languages.
Solution:
-
In Python, use explicit type annotations:
@dataclass
class Data:
value: pyfory.Int32Type # Not just 'int' -
Ensure integer ranges are compatible:
int8: -128 to 127int16: -32,768 to 32,767int32: -2,147,483,648 to 2,147,483,647
Float Precision Loss
Symptom: Float values have unexpected precision.
Cause: Mixing float32 and float64 types.
Solution:
-
Use consistent float types:
@dataclass
class Data:
value: pyfory.Float32Type # Explicit 32-bit float -
Be aware that Python's
floatmaps tofloat64by default
String Encoding Errors
Symptom:
Error: Invalid UTF-8 sequence
Cause: Non-UTF-8 encoded strings.
Solution:
-
Ensure all strings are valid UTF-8
-
In Python, decode bytes before serialization:
text = raw_bytes.decode('utf-8')
Field Order Issues
"Field mismatch" Error
Symptom: Deserialized objects have wrong field values.
Cause: Field order differs between languages.
Solution: Fory sorts fields by their snake_cased names. Ensure field names are consistent:
// Java - fields will be sorted: age, email, name
public class Person {
public String name;
public int age;
public String email;
}
# Python - same field order
@dataclass
class Person:
name: str
age: pyfory.Int32Type
email: str
Reference Tracking Issues
Stack Overflow with Circular References
Symptom:
StackOverflowError or RecursionError
Cause: Reference tracking is disabled but data has circular references.
Solution: Enable reference tracking:
// Java
Fory fory = Fory.builder()
.withLanguage(Language.XLANG)
.withRefTracking(true)
.build();
# Python
fory = pyfory.Fory(ref_tracking=True)
Duplicate Objects
Symptom: Shared objects are duplicated after deserialization.
Cause: Reference tracking is disabled.
Solution: Enable reference tracking if objects are shared within the graph.