Repository: serde-rs/json (language: rust)

Issue:
u128 as hashmap key results in invalid json
See example output here being invalid json (key not quoted): [playground link](https://play.integer32.com/?version=stable&mode=debug&edition=2018&gist=c026aab61d8559c539d5742cb3b498ee)


Discussion / hints:
Forgot to mention, works ok for u64

Fix patch:
diff --git a/src/ser.rs b/src/ser.rs
index d0fc66a4b..463c15a16 100644
--- a/src/ser.rs
+++ b/src/ser.rs
@@ -987,10 +987,22 @@ where
 
     serde_if_integer128! {
         fn serialize_i128(self, value: i128) -> Result<()> {
-            self.ser
+            try!(self
+                .ser
+                .formatter
+                .begin_string(&mut self.ser.writer)
+                .map_err(Error::io));
+            try!(self
+                .ser
                 .formatter
                 .write_number_str(&mut self.ser.writer, &value.to_string())
-                .map_err(Error::io)
+                .map_err(Error::io));
+            try!(self
+                .ser
+                .formatter
+                .end_string(&mut self.ser.writer)
+                .map_err(Error::io));
+            Ok(())
         }
     }
 
@@ -1072,10 +1084,22 @@ where
 
     serde_if_integer128! {
         fn serialize_u128(self, value: u128) -> Result<()> {
-            self.ser
+            try!(self
+                .ser
+                .formatter
+                .begin_string(&mut self.ser.writer)
+                .map_err(Error::io));
+            try!(self
+                .ser
                 .formatter
                 .write_number_str(&mut self.ser.writer, &value.to_string())
-                .map_err(Error::io)
+                .map_err(Error::io));
+            try!(self
+                .ser
+                .formatter
+                .end_string(&mut self.ser.writer)
+                .map_err(Error::io));
+            Ok(())
         }
     }
 


Test patch:
diff --git a/tests/test.rs b/tests/test.rs
index 46b3396eb..548f71a32 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1782,6 +1782,16 @@ fn test_integer_key() {
     )]);
 }
 
+#[test]
+fn test_integer128_key() {
+    let map = treemap! {
+        100000000000000000000000000000000000000u128 => ()
+    };
+    let j = r#"{"100000000000000000000000000000000000000":null}"#;
+    assert_eq!(to_string(&map).unwrap(), j);
+    assert_eq!(from_str::<BTreeMap<u128, ()>>(j).unwrap(), map);
+}
+
 #[test]
 fn test_deny_float_key() {
     #[derive(Eq, PartialEq, Ord, PartialOrd)]