Skip to content

Commit 41e1bc8

Browse files
committed
Python: Serialize large integers as strings in RPC to avoid Jackson limits
Jackson 2.15+ rejects JSON numbers exceeding 1000 digits via StreamReadConstraints.getMaxNumberLength(). Python integers have no size limit, so a literal like paramiko's 4096-bit DH prime (1234 decimal digits) was serialized as a raw JSON number, causing deserialization to fail on the Java side. Convert integers exceeding Java's long range to strings before serialization. The original source representation is preserved in the literal's valueSource field, so printing is unaffected.
1 parent 78d3500 commit 41e1bc8

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

rewrite-python/rewrite/src/rewrite/rpc/send_queue.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,14 @@ def _get_primitive_value(self, obj: Any) -> Any:
316316
return None
317317
if isinstance(obj, bool):
318318
return obj
319-
if isinstance(obj, (int, str)):
319+
if isinstance(obj, int):
320+
# Integers exceeding Java's long range cannot be serialized as
321+
# JSON numbers (Jackson's StreamReadConstraints rejects them).
322+
# Convert to string — the original source is preserved in valueSource.
323+
if obj > 9223372036854775807 or obj < -9223372036854775808:
324+
return str(obj)
325+
return obj
326+
if isinstance(obj, str):
320327
return obj
321328
if isinstance(obj, float):
322329
# Special float values (inf, nan) are not valid JSON

0 commit comments

Comments
 (0)