version stringclasses 2
values | instance_id stringlengths 17 19 | pull_number int64 31 1.18k | issue_numbers listlengths 1 2 | created_at stringlengths 20 20 | hints_text stringlengths 0 3.56k | base_commit stringlengths 40 40 | problem_statement stringlengths 94 8.7k | patch stringlengths 441 52k | test_patch stringlengths 298 13k | repo stringclasses 1
value | environment_setup_commit stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
1.0 | serde-rs__json-1175 | 1,175 | [
"877"
] | 2024-08-12T18:26:05Z | @dtolnay Have you had a chance to look into this? It'd be great to get your review. | cf771a0471dd797b6fead77e767f2f7943740c98 | Deserialize invalid UTF-8 into byte bufs as WTF-8
Previously #828 added support for deserializing lone leading and
trailing surrogates into WTF-8 encoded bytes when deserializing a string
as bytes. This commit extends this to cover the case of a leading
surrogate followed by code units that are not trailing surrogat... | diff --git a/src/de.rs b/src/de.rs
index bfde371a1..bd6f2e50c 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -1575,7 +1575,10 @@ impl<'de, 'a, R: Read<'de>> de::Deserializer<'de> for &'a mut Deserializer<R> {
///
/// The behavior of serde_json is specified to fail on non-UTF-8 strings
/// when deserializing i... | diff --git a/tests/test.rs b/tests/test.rs
index 9f2159513..4290cb3ef 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1707,7 +1707,7 @@ fn test_byte_buf_de() {
}
#[test]
-fn test_byte_buf_de_lone_surrogate() {
+fn test_byte_buf_de_invalid_surrogates() {
let bytes = ByteBuf::from(vec![237, 160, 188]);
l... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 |
1.0 | serde-rs__json-1055 | 1,055 | [
"1054"
] | 2023-08-15T21:59:39Z | 8652bf2bc5dac3b5496725452cfe14ca573f6232 | Cannot deserialize to `HashMap<bool, _>`
JSON objects can only have string keys, although `HashMap`s can have many types of keys. In the case of `i32` keys (eg `HashMap<i32, i32>`), serde_json coerces the stringified integer key (eg `"1"`) into `1i32`. However, that fails in the case of `bool` keys; it raises an erro... | diff --git a/src/de.rs b/src/de.rs
index 7aad50b96..9975b40a5 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -2203,6 +2203,41 @@ where
deserialize_numeric_key!(deserialize_f32, deserialize_f32);
deserialize_numeric_key!(deserialize_f64);
+ fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value>
+ wher... | diff --git a/tests/test.rs b/tests/test.rs
index 8d9a5942a..e548b7dae 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1654,17 +1654,6 @@ fn test_deserialize_from_stream() {
assert_eq!(request, response);
}
-#[test]
-fn test_serialize_rejects_bool_keys() {
- let map = treemap!(
- true => 2,
- ... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-1045 | 1,045 | [
"423"
] | 2023-07-26T19:15:09Z | 8f90eacf6c6335fbd925b1d663e46f4a7592ebba | Implement IntoDeserializer for Value and &Value
An `IntoDeserializer` impl would provide a way to deserialize from these types while constructing exactly the right error type on failure, rather than constructing a `serde_json::Error` and mapping it to a custom error of the target type through its `Display` impl.
```... | diff --git a/src/value/de.rs b/src/value/de.rs
index 3f14abb3b..2090dd009 100644
--- a/src/value/de.rs
+++ b/src/value/de.rs
@@ -482,6 +482,14 @@ impl<'de> IntoDeserializer<'de, Error> for Value {
}
}
+impl<'de> IntoDeserializer<'de, Error> for &'de Value {
+ type Deserializer = Self;
+
+ fn into_deserial... | diff --git a/tests/test.rs b/tests/test.rs
index acf5de480..8d9a5942a 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -2472,6 +2472,12 @@ fn test_value_into_deserializer() {
let mut map = BTreeMap::new();
map.insert("inner", json!({ "string": "Hello World" }));
+ let outer = Outer::deserialize(serde::d... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-1005 | 1,005 | [
"1004"
] | 2023-03-27T16:41:41Z | 02e583360db1a4aa7d21db911a9b62f34161c386 | `Number` loses precision on f32s
Hi there, I've gone through a couple of issues but haven't found anything that quite matches my problem, so if this is a duplicate, feel free to close this and direct me elsewhere :)
The following small snippet replicates my issue:
```rs
use serde::{Deserialize, Serialize};
use se... | diff --git a/src/number.rs b/src/number.rs
index 21a76411c..5ecbde873 100644
--- a/src/number.rs
+++ b/src/number.rs
@@ -279,6 +279,35 @@ impl Number {
}
}
+ pub(crate) fn as_f32(&self) -> Option<f32> {
+ #[cfg(not(feature = "arbitrary_precision"))]
+ match self.n {
+ N::PosI... | diff --git a/tests/regression/issue1004.rs b/tests/regression/issue1004.rs
new file mode 100644
index 000000000..3f5bd96aa
--- /dev/null
+++ b/tests/regression/issue1004.rs
@@ -0,0 +1,12 @@
+#![cfg(feature = "arbitrary_precision")]
+
+#[test]
+fn test() {
+ let float = 5.55f32;
+ let value = serde_json::to_value(... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-956 | 956 | [
"953"
] | 2022-11-22T06:28:36Z | 586fefb5a1e619b0f1a82d94b52ce25754b73ea0 | Invalid JSON values are accepted: numbers with trailing dot but only if greater than u64::MAX
According to JSON spec, both of these should be errors:
```rust
fn main() {
let x1: Result<serde_json::Value, _> = serde_json::from_str("18446744073709551615.");
assert!(x1.is_err());
let x2: Result<serde_js... | diff --git a/src/de.rs b/src/de.rs
index 378b71062..88d0f2624 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -451,30 +451,33 @@ impl<'de, R: Read<'de>> Deserializer<R> {
&mut self,
positive: bool,
mut significand: u64,
- mut exponent: i32,
+ exponent_before_decimal_point: i32,
)... | diff --git a/tests/regression/issue953.rs b/tests/regression/issue953.rs
new file mode 100644
index 000000000..771aa5287
--- /dev/null
+++ b/tests/regression/issue953.rs
@@ -0,0 +1,9 @@
+use serde_json::Value;
+
+#[test]
+fn test() {
+ let x1 = serde_json::from_str::<Value>("18446744073709551615.");
+ assert!(x1.... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-848 | 848 | [
"845"
] | 2022-01-16T00:41:56Z | 66919777d0c31addd190c7a48ec78145a270294d | `arbitrary_precision` Breaks Visitors
I'm not sure if I'm doing something wrong here, but I'm trying to write a type that can deserialize from either strings or integers.
Initially I did this using an `untagged` enumeration variant to do the heavy lifting - see [here](https://github.com/influxdata/pbjson/blob/26626... | diff --git a/src/de.rs b/src/de.rs
index b4c5ef7dc..bf103f04b 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -864,6 +864,15 @@ impl<'de, R: Read<'de>> Deserializer<R> {
buf.push('-');
}
self.scan_integer(&mut buf)?;
+ if positive {
+ if let Ok(unsigned) = buf.parse() {
+ ... | diff --git a/tests/regression/issue845.rs b/tests/regression/issue845.rs
new file mode 100644
index 000000000..dcca55694
--- /dev/null
+++ b/tests/regression/issue845.rs
@@ -0,0 +1,72 @@
+use serde::{Deserialize, Deserializer};
+use std::convert::TryFrom;
+use std::fmt::{self, Display};
+use std::marker::PhantomData;
+... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-801 | 801 | [
"799"
] | 2021-09-14T20:01:13Z | b419f2e0650ab959a3db0b0ca471269e81abf27f | Preserve sign on negative zero f32
`-0` is parsed as `0` for `f32` type.
Is it intentional? I know that this is an edge case, but this is somewhat important for my use case, because it technically two different values.
rustc 1.54.0, serde_json v1.0.67
| diff --git a/src/de.rs b/src/de.rs
index 7cc9f9b8e..a2f34b908 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -434,8 +434,8 @@ impl<'de, R: Read<'de>> Deserializer<R> {
} else {
let neg = (significand as i64).wrapping_neg();
- // Convert into a float if we underflow.... | diff --git a/tests/test.rs b/tests/test.rs
index 9fdf26cc7..d6a0e81c1 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -805,6 +805,7 @@ fn test_parse_u64() {
#[test]
fn test_parse_negative_zero() {
for negative_zero in &[
+ "-0",
"-0.0",
"-0e2",
"-0.0e2",
| serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-796 | 796 | [
"795"
] | 2021-08-28T18:22:46Z | 7b4585fbff5962f05ffb1d7b5a296cf35b69072e | Deserialization from Value fails to catch unknown fields in struct variant
This is an inconsistency between `from_str` and `from_value`. In general these are supposed to have the same behavior on identical input.
```rust
use serde::de::{
Deserialize, Deserializer, EnumAccess, IgnoredAny, MapAccess, VariantAcce... | diff --git a/src/value/de.rs b/src/value/de.rs
index 5ff011961..24ca82696 100644
--- a/src/value/de.rs
+++ b/src/value/de.rs
@@ -538,7 +538,7 @@ impl<'de> VariantAccess<'de> for VariantDeserializer {
V: Visitor<'de>,
{
match self.value {
- Some(Value::Object(v)) => visitor.visit_map(Ma... | diff --git a/tests/regression/issue795.rs b/tests/regression/issue795.rs
new file mode 100644
index 000000000..43198a33d
--- /dev/null
+++ b/tests/regression/issue795.rs
@@ -0,0 +1,57 @@
+use serde::de::{
+ Deserialize, Deserializer, EnumAccess, IgnoredAny, MapAccess, VariantAccess, Visitor,
+};
+use serde_json::jso... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-786 | 786 | [
"785"
] | 2021-07-17T03:32:52Z | ea39063f9c8c7dde4ac43bbd9843287bece59b1a | With feature "arbitrary_precision" exponent marker get converted to lowercase
Comment in [`Cargo.toml`](https://github.com/serde-rs/json/blob/ea39063f9c8c7dde4ac43bbd9843287bece59b1a/Cargo.toml#L71) for feature `arbitrary_precision` states:
> This feature makes `JSON` -> `serde_json::Number` -> `JSON` produce output i... | diff --git a/src/de.rs b/src/de.rs
index 15c8236b6..1824117a0 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -898,7 +898,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
fn scan_number(&mut self, buf: &mut String) -> Result<()> {
match tri!(self.peek_or_null()) {
b'.' => self.scan_decimal(buf),
- ... | diff --git a/tests/test.rs b/tests/test.rs
index 2fe7c560a..3d701d827 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1007,8 +1007,14 @@ fn test_parse_number() {
#[cfg(feature = "arbitrary_precision")]
test_parse_ok(vec![
("1e999", Number::from_string_unchecked("1e999".to_owned())),
+ ("1e+... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-757 | 757 | [
"755"
] | 2021-02-28T04:47:02Z | 9bcb08fd926c1c727cb1343363d41c25f2e6025d | Panic on input that is not valid UTF8 when deserializing to a RawValue
Very similar to this issue: https://github.com/serde-rs/json/issues/99
However, I ran into this problem when deserializing to a RawValue.
```
let json_str2 = &[ b'"', b'\xCE', b'\xF8', b'"'];
let v2: serde_json::Result<Box<serde_json::value:... | diff --git a/src/read.rs b/src/read.rs
index 522c0e011..574857cd8 100644
--- a/src/read.rs
+++ b/src/read.rs
@@ -587,7 +587,10 @@ impl<'a> Read<'a> for SliceRead<'a> {
V: Visitor<'a>,
{
let raw = &self.slice[self.raw_buffering_start_index..self.index];
- let raw = str::from_utf8(raw).unwra... | diff --git a/tests/test.rs b/tests/test.rs
index ffe58c979..2fe7c560a 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -2201,6 +2201,25 @@ fn test_boxed_raw_value() {
assert_eq!(r#"["a",42,{"foo": "bar"},null]"#, array_to_string);
}
+#[cfg(feature = "raw_value")]
+#[test]
+fn test_raw_invalid_utf8() {
+ use... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-648 | 648 | [
"647"
] | 2020-04-04T23:17:05Z | fd6741f4b0b3fc90a58a6f578e33a9adc6403f3f | StreamDeserializer enters a busy-loop for malformed input
See the test in
https://github.com/oli-obk/cargo_metadata/pull/106/commits/ea84dc353dc4367c507eec0f4fd1f73892cf4d28
There, the `for message in stream_deserilizer` loop loops infinitelly, because serde repeteadly tries to parse the same invalid portion of i... | diff --git a/src/de.rs b/src/de.rs
index 1a7192672..890a51687 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -151,6 +151,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
StreamDeserializer {
de: self,
offset: offset,
+ failed: false,
output: PhantomData,
... | diff --git a/tests/stream.rs b/tests/stream.rs
index 9fabe0de2..ca54e9a15 100644
--- a/tests/stream.rs
+++ b/tests/stream.rs
@@ -169,3 +169,14 @@ fn test_json_stream_invalid_number() {
assert_eq!(second.to_string(), "trailing characters at line 1 column 2");
});
}
+
+#[test]
+fn test_error() {
+ let d... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-525 | 525 | [
"524"
] | 2019-03-19T09:15:01Z | Thanks, I would accept a PR to return an EOF error in this case. | e6b02d1b53cf1c685db9e20f6a300e8f22a9bf00 | StreamDeserializer errors on cut-off decimal numbers
Simple example:
```rust
fn main() {
dbg!(serde_json::Deserializer::from_slice(b"[1.").into_iter::<Vec<f64>>().next());
}
```
I'd expect that to return None or an EOF error - the array is not finished yet and the number is valid if it's followed by more digi... | diff --git a/src/de.rs b/src/de.rs
index e3effc365..f8d4ace53 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -380,7 +380,14 @@ impl<'de, R: Read<'de>> Deserializer<R> {
}
fn parse_integer(&mut self, positive: bool) -> Result<ParserNumber> {
- match try!(self.next_char_or_null()) {
+ let next = matc... | diff --git a/tests/stream.rs b/tests/stream.rs
index 7127b2534..88a395294 100644
--- a/tests/stream.rs
+++ b/tests/stream.rs
@@ -81,6 +81,36 @@ fn test_json_stream_truncated() {
});
}
+#[test]
+fn test_json_stream_truncated_decimal() {
+ let data = "{\"x\":4.";
+
+ test_stream!(data, Value, |stream| {
+ ... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 |
1.0 | serde-rs__json-521 | 521 | [
"520"
] | 2019-02-28T08:59:36Z | 6ac689b2b327ed00e8a56d812a5c860177ab10dd | Error roundtripping (regression from 1.0.25 to 1.0.38)
We need to roundtrip an enum that has an element `Float(f32)`. That used to work with 1.0.25, but fails with 1.0.38. [This gist](https://gist.github.com/lutter/2820e2c98331d5b5b6b95d62912e2e0f) has complete code that demonstrates the problem.
What happens is tha... | diff --git a/Cargo.toml b/Cargo.toml
index 168a40df3..dd912d69c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,6 +22,7 @@ itoa = "0.4.3"
ryu = "0.2"
[dev-dependencies]
+automod = "0.1"
compiletest_rs = { version = "0.3", features = ["stable"] }
serde_bytes = "0.10"
serde_derive = "1.0"
diff --git a/src/number.r... | diff --git a/tests/regression.rs b/tests/regression.rs
new file mode 100644
index 000000000..eff29ff6c
--- /dev/null
+++ b/tests/regression.rs
@@ -0,0 +1,6 @@
+extern crate automod;
+extern crate serde;
+extern crate serde_derive;
+
+#[path = "regression/mod.rs"]
+mod regression;
diff --git a/tests/regression/issue520.... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-512 | 512 | [
"511"
] | 2019-01-16T21:56:30Z | Forgot to mention, works ok for u64 | 22c0c7e92fe93d0c0f8ee1a1fcf3588290975d53 | 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)
| 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
... | 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 ... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 |
1.0 | serde-rs__json-506 | 506 | [
"502"
] | 2018-12-29T09:22:21Z | Thanks! I would accept a PR to support u128 => Value in the case that arbitrary_precision is enabled. | 32f1568c2a280d3456c566c811680f5bd65fd7f3 | u128 doesn't work for Value
Looks like there's a bug in serde_json. This program:
```
#[macro_use]
extern crate serde_json;
use std::str::FromStr;
fn main() {
let string = format!("{}", u128::max_value());
println!("{}", string);
let val = serde_json::value::Value::from_str(&string);
let va... | diff --git a/src/value/ser.rs b/src/value/ser.rs
index 172784cce..c377b533d 100644
--- a/src/value/ser.rs
+++ b/src/value/ser.rs
@@ -77,6 +77,13 @@ impl serde::Serializer for Serializer {
Ok(Value::Number(value.into()))
}
+ serde_if_integer128! {
+ #[cfg(feature = "arbitrary_precision")]
+ ... | diff --git a/tests/test.rs b/tests/test.rs
index 97da8133a..c08645a02 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1909,6 +1909,13 @@ fn test_partialeq_number() {
);
}
+#[test]
+#[cfg(integer128)]
+#[cfg(feature = "arbitrary_precision")]
+fn test_partialeq_integer128() {
+ number_partialeq_ok!(i128::MI... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 |
1.0 | serde-rs__json-493 | 493 | [
"492"
] | 2018-10-04T05:25:14Z | 805f394f8b4165e4f365c27068eedc1d9cb6ac52 | Malformed number causes panic in de.rs
The following test case demonstrates the problem. This could be used for DOSing Rust web apps.
```rust
extern crate serde_json;
#[test]
fn parse_json() {
let f: Result<f64, _> = serde_json::from_str("3.5E-2147483647");
}
```
```
stack backtrace:
0: std::sys::... | diff --git a/src/de.rs b/src/de.rs
index 70ebf0d5e..020869a64 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -676,7 +676,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
) -> Result<f64> {
let mut f = significand as f64;
loop {
- match POW10.get(exponent.abs() as usize) {
+ match P... | diff --git a/tests/test.rs b/tests/test.rs
index 954ac901b..688dfe5db 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -860,6 +860,7 @@ fn test_parse_f64() {
("0.00e00", 0.0),
("0.00e+00", 0.0),
("0.00e-00", 0.0),
+ ("3.5E-2147483647", 0.0),
(
&format!("{}", (i64... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-485 | 485 | [
"355"
] | 2018-09-20T08:49:13Z | @dtolnay mentions that the work happening in #416 might lay some groundwork for such a change to take place.
Yeah, this sounds useful. Ideally we could get some of the building blocks for this sort of thing (custom 'built-in' types) integrated into serde itself, in time.
I need this for a project I'm working on, and wo... | b0e3a9798b95ea95d7fcc5d38b9e62010d367557 | Add a RawValue type
It would be helpful to have a type similar to Go's [`json.RawMessage`](https://golang.org/pkg/encoding/json/#RawMessage) that is not tokenized during deserialization, but rather its raw contents stored as a `Vec<u8>` or `&'de [u8]`.
The following pseudo-code demonstrates the idea.
```rust
#[der... | diff --git a/Cargo.toml b/Cargo.toml
index 2f8ebe5ca..0ccec383a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,6 +26,12 @@ compiletest_rs = "0.3"
serde_bytes = "0.10"
serde_derive = "1.0"
+[package.metadata.docs.rs]
+features = ["raw_value"]
+
+[package.metadata.playground]
+features = ["raw_value"]
+
### FEATU... | diff --git a/tests/test.rs b/tests/test.rs
index 08d038837..ec2de425e 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -938,9 +938,9 @@ fn test_serialize_char() {
#[test]
fn test_malicious_number() {
#[derive(Serialize)]
- #[serde(rename = "$__serde_private_Number")]
+ #[serde(rename = "$serde_json::priva... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 |
1.0 | serde-rs__json-480 | 480 | [
"355"
] | 2018-09-14T10:25:28Z | @dtolnay mentions that the work happening in #416 might lay some groundwork for such a change to take place.
Yeah, this sounds useful. Ideally we could get some of the building blocks for this sort of thing (custom 'built-in' types) integrated into serde itself, in time.
I need this for a project I'm working on, and wo... | d4612639020d4e744cb755e63430b7f95e566c7a | Add a RawValue type
It would be helpful to have a type similar to Go's [`json.RawMessage`](https://golang.org/pkg/encoding/json/#RawMessage) that is not tokenized during deserialization, but rather its raw contents stored as a `Vec<u8>` or `&'de [u8]`.
The following pseudo-code demonstrates the idea.
```rust
#[der... | diff --git a/src/de.rs b/src/de.rs
index f1c5c3cff..0ad91a2a8 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -8,6 +8,7 @@
//! Deserialize JSON data to a Rust data structure.
+use std::borrow::Cow;
use std::io;
use std::marker::PhantomData;
use std::result;
@@ -946,6 +947,22 @@ impl<'de, R: Read<'de>> Deserializer<R>... | diff --git a/tests/test.rs b/tests/test.rs
index 08d038837..09c51a62d 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -44,7 +44,7 @@ use serde_bytes::{ByteBuf, Bytes};
use serde_json::{
from_reader, from_slice, from_str, from_value, to_string, to_string_pretty, to_value, to_vec,
- to_writer, Deserializer, ... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 |
1.0 | serde-rs__json-462 | 462 | [
"461"
] | 2018-07-16T16:38:33Z | 1b36cec484a24dc8d1700cf2ef0577a96d4d7b6f | Unused result warning in json! macro.
Stumbled upon a warning coming from the `json!` macro that will cause compiles to fail if the `unused_results` warning is set with [this test case](http://play.rust-lang.org/?gist=baf66a86706282966f5109f537b74041&version=stable&mode=debug&edition=2015). Here's what I get running it... | diff --git a/src/macros.rs b/src/macros.rs
index 29e16b7ab..a3accf75b 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -161,7 +161,7 @@ macro_rules! json_internal {
// Insert the current entry followed by trailing comma.
(@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
- $obje... | diff --git a/tests/test.rs b/tests/test.rs
index 4e9c0ccd9..08d038837 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1847,6 +1847,9 @@ fn test_json_macro() {
(<Result<&str, ()> as Clone>::clone(&Ok("")).unwrap()): "ok",
(<Result<(), &str> as Clone>::clone(&Err("")).unwrap_err()): "err"
});
+
... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-455 | 455 | [
"454"
] | 2018-06-24T23:27:48Z | 7efc0972cd04fc05e028d4d7f5b95359b82d878b | Get ExpectedSomeIdent error instead of Eof error if the input ends with a truncated "null"
```rust
extern crate serde_json;
fn main() {
match serde_json::from_str::<serde_json::Value>("nu") {
Ok(_) => unreachable!(),
Err(err) => match err.classify() {
serde_json::error::Category:... | diff --git a/src/de.rs b/src/de.rs
index b154cad60..f1c5c3cff 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -308,9 +308,16 @@ impl<'de, R: Read<'de>> Deserializer<R> {
}
fn parse_ident(&mut self, ident: &[u8]) -> Result<()> {
- for c in ident {
- if Some(*c) != try!(self.next_char()) {
- ... | diff --git a/tests/test.rs b/tests/test.rs
index 0b84ce869..811c409af 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -613,6 +613,15 @@ where
let mut de = Deserializer::from_str(&twoline);
IgnoredAny::deserialize(&mut de).unwrap();
assert_eq!(0xDEAD_BEEF, u64::deserialize(&mut de).unwrap())... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-449 | 449 | [
"448"
] | 2018-05-26T22:05:01Z | 8ffe4d8222d35aae79456ee5eff72db5236fc8df | Support i128 and u128
These types gained Serialize and Deserialize impls in [Serde 1.0.60](https://github.com/serde-rs/serde/releases/tag/v1.0.60) but still needs to be implemented in serde_json.
| diff --git a/Cargo.toml b/Cargo.toml
index 938cf314f..0216476d8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,7 +16,7 @@ travis-ci = { repository = "serde-rs/json" }
appveyor = { repository = "serde-rs/json" }
[dependencies]
-serde = "1.0"
+serde = "1.0.60"
linked-hash-map = { version = "0.5", optional = true }
... | diff --git a/tests/test.rs b/tests/test.rs
index 61e0d2dc9..a7d21092f 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1983,3 +1983,40 @@ fn null_invalid_type() {
String::from("invalid type: null, expected a string at line 1 column 4")
);
}
+
+#[test]
+fn test_integer128() {
+ let signed = &[i128::m... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 | |
1.0 | serde-rs__json-356 | 356 | [
"174"
] | 2017-09-04T19:20:12Z | The Pikkr benchmark will be a good way to measure this https://github.com/pikkr/pikkr. They ignore most of the data. | b67a9470c59ab8445e145e74a6a5398142e06e21 | Performance of deserializing IgnoredAny
I haven't benchmarked but there may be an opportunity to optimize IgnoredAny. Currently the codepath for deserialize_ignored_any is the same as for deserializing a serde_json::Value. It jumps back and forth into the IgnoredAny's Visitor and does all of the work that entails, incl... | diff --git a/src/de.rs b/src/de.rs
index 9ec5165f9..fd2a4894d 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -532,6 +532,215 @@ impl<'de, R: Read<'de>> Deserializer<R> {
None => Err(self.peek_error(ErrorCode::EofWhileParsingObject)),
}
}
+
+ fn ignore_value(&mut self) -> Result<()> {
+ l... | diff --git a/tests/test.rs b/tests/test.rs
index 89b1d783e..f8ccd0c5d 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -34,7 +34,7 @@ use std::iter;
use std::marker::PhantomData;
use std::{u8, u16, u32, u64};
-use serde::de::{self, Deserialize};
+use serde::de::{self, Deserialize, IgnoredAny};
use serde::ser::{se... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 |
1.0 | serde-rs__json-353 | 353 | [
"352"
] | 2017-09-01T18:40:41Z | I agree! Would you be interested in implementing this? The code for parsing a map key will need to recognize when it gets a `}` and treat that as a trailing comma error.
I'll give it a go.
Is there documentation on contributing? It seems like the tests don't compile on rustc stable...
I switched to nightly and the test... | 764e9607cf5d5a66e6a8447320b9d938d59f3806 | misleading error message
I was going through the [serde_json :: de :: from_reader](https://docs.serde.rs/serde_json/de/fn.from_reader.html) example and encountered an error at run time "KeyMustBeAString". I went back to my json file and looked. All of the keys were strings... I scratched my head and stared. Then I noti... | diff --git a/src/de.rs b/src/de.rs
index fd2a4894d..0d5225398 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -105,6 +105,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
/// only has trailing whitespace.
pub fn end(&mut self) -> Result<()> {
match try!(self.parse_whitespace()) {
+ Some(b',') => E... | diff --git a/tests/test.rs b/tests/test.rs
index f8ccd0c5d..84861b6db 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -894,7 +894,7 @@ fn test_parse_list() {
("[ ", "EOF while parsing a list at line 1 column 2"),
("[1", "EOF while parsing a list at line 1 column 2"),
("[1,", "EO... | serde-rs/json | cf771a0471dd797b6fead77e767f2f7943740c98 |
0.9 | serde-rs__json-303 | 303 | [
"183"
] | 2017-04-12T17:13:41Z | a22a06f74faf8bff4e474968d4a6d666125af54b | Expose number of bytes processed by StreamDeserializer
Use case from IRC:
> **\<Yorhel>** Hi everyone. Does serde_json support decoding JSON with trailing data?
> **\<Yorhel>** E.g. I'd like to do something in the form of: let (val, data) = serde_json::from_str("{}garbage");
> **\<Yorhel>** With val being the pars... | diff --git a/src/de.rs b/src/de.rs
index db61ef8c3..29b68ef64 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -97,8 +97,10 @@ impl<'de, R: Read<'de>> Deserializer<R> {
{
// This cannot be an implementation of std::iter::IntoIterator because
// we need the caller to choose what T is.
+ let offset... | diff --git a/tests/stream.rs b/tests/stream.rs
new file mode 100644
index 000000000..e4f573098
--- /dev/null
+++ b/tests/stream.rs
@@ -0,0 +1,109 @@
+#![cfg(not(feature = "preserve_order"))]
+
+extern crate serde;
+
+#[macro_use]
+extern crate serde_json;
+
+use serde_json::{Deserializer, Value};
+
+macro_rules! test_s... | serde-rs/json | a22a06f74faf8bff4e474968d4a6d666125af54b | |
null | serde-rs__json-302 | 302 | [
"266"
] | 2017-04-12T04:11:39Z | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | Combine serde_json and serde_json_tests into one crate
These have been separated historically because it was not possible for serde_json to have an optional dev-dependency on serde_derive (https://github.com/rust-lang/cargo/issues/1596).
Now that serde_derive is not optional, it would be simpler to structure the rep... | diff --git a/Cargo.toml b/Cargo.toml
index ed69eecdc..e7c52d24f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,31 @@
-[workspace]
-members = [
- "json",
- "json_tests",
-]
+[package]
+name = "serde_json"
+version = "0.9.10"
+authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
+license = "MIT/Apache-2.0... | diff --git a/json_tests/Cargo.toml b/json_tests/Cargo.toml
deleted file mode 100644
index e3c2711e5..000000000
--- a/json_tests/Cargo.toml
+++ /dev/null
@@ -1,18 +0,0 @@
-[package]
-name = "serde_json_tests"
-version = "0.0.0"
-authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
-publish = false
-
-[features]
-tr... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-301 | 301 | [
"300"
] | 2017-04-11T23:28:29Z | 565e692cafafbf16a960de43d98f29d438fe461a | StreamDeserializer should only accept arrays and objects
```json
// ok
{"a":0}{"a":1}
// not ok
falsetrue
// also not ok
false true
```
Supersedes #56 which intended to support other types as long as they were separated by whitespace. I am open to extending support to types in the future as long as somebo... | diff --git a/json/src/de.rs b/json/src/de.rs
index cad22c792..a0efe53ed 100644
--- a/json/src/de.rs
+++ b/json/src/de.rs
@@ -992,13 +992,17 @@ impl<'de, 'a, R: Read<'de> + 'a> de::VariantVisitor<'de> for UnitVariantVisitor<
/// A stream deserializer can be created from any JSON deserializer using the
/// `Deserialize... | diff --git a/json_tests/tests/test.rs b/json_tests/tests/test.rs
index 93f273d33..4500f9fec 100644
--- a/json_tests/tests/test.rs
+++ b/json_tests/tests/test.rs
@@ -31,6 +31,7 @@ use serde_bytes::{ByteBuf, Bytes};
use serde_json::{
Deserializer,
+ Map,
Value,
from_iter,
from_reader,
@@ -1670,6... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-295 | 295 | [
"294"
] | 2017-04-11T18:06:29Z | f5094829a885d78d0dd1d3797f9e730df13a7a71 | Remove ToJson trait
This trait was ripped directly from [`rustc_serialize::json::ToJson`](https://docs.rs/rustc-serialize/0.3.23/rustc_serialize/json/trait.ToJson.html) but the point was lost by providing an impl ToJson for T where T: Serialize. The rustc_serialize trait is infallible and there are impls for standard l... | diff --git a/json/src/macros.rs b/json/src/macros.rs
index 4145737de..e4dbb72ba 100644
--- a/json/src/macros.rs
+++ b/json/src/macros.rs
@@ -266,6 +266,6 @@ macro_rules! json_internal {
// Any Serialize type: numbers, strings, struct literals, variables etc.
// Must be below every other rule.
($other:exp... | diff --git a/json_tests/tests/test.rs b/json_tests/tests/test.rs
index 81c4d6e97..93f273d33 100644
--- a/json_tests/tests/test.rs
+++ b/json_tests/tests/test.rs
@@ -31,7 +31,6 @@ use serde_bytes::{ByteBuf, Bytes};
use serde_json::{
Deserializer,
- Error,
Value,
from_iter,
from_reader,
@@ -44,7... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-278 | 278 | [
"245"
] | 2017-03-12T20:40:52Z | Let's add:
- is_eof()
- is_syntax()
- is_io()
where I think eof errors are not syntax errors.
Just to clarify, if I have a struct, let's say:
```rust
#[derive(deserialize)]
struct Point {
x: u64,
y: u64,
};
```
And pass this JSON:
```json
{"a": 16}
```
What kind of error is this? It's no... | b4adb3c4a4eb32645884fd48485eb56e0c650b07 | Expose whether error is caused by EOF
In streaming use cases you want to treat `{"x": true,` differently from `{]`. One of them you retry later once you have more data, the other is just an error.
cc @vorner
| diff --git a/json/src/de.rs b/json/src/de.rs
index 864619eba..b93aad75e 100644
--- a/json/src/de.rs
+++ b/json/src/de.rs
@@ -159,7 +159,7 @@ impl<R: Read> Deserializer<R> {
where V: de::Visitor,
{
if try!(self.parse_whitespace()) { // true if eof
- return Err(self.peek_error(ErrorCode:... | diff --git a/json_tests/tests/test.rs b/json_tests/tests/test.rs
index 83e09f95e..b90ce6765 100644
--- a/json_tests/tests/test.rs
+++ b/json_tests/tests/test.rs
@@ -1907,3 +1907,28 @@ fn test_partialeq_string() {
assert_eq!(v, String::from("42"));
assert_eq!(String::from("42"), v);
}
+
+#[test]
+fn test_cate... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-276 | 276 | [
"275"
] | 2017-03-09T01:18:07Z | 5256c7ba5fb16d9235dd8d5b01c78e2aea19a404 | Better errors when json! fails to parse colon or comma
```rust
json!({:true})
```
```
error: expected expression, found `:`
--> src/main.rs:19:5
|
5 | json!({:true})
| ^^^^^^^^^^^^^^
```
```rust
json!({"a",})
```
```
error: expected expression, found `,`
--> src/main.rs:20:5
|
5 |... | diff --git a/json/src/macros.rs b/json/src/macros.rs
index e68df8fcd..4145737de 100644
--- a/json/src/macros.rs
+++ b/json/src/macros.rs
@@ -134,16 +134,19 @@ macro_rules! json_internal {
// TT muncher for parsing the inside of an object {...}. Each entry is
// inserted into the given map variable.
//
- ... | diff --git a/json_tests/Cargo.toml b/json_tests/Cargo.toml
index bdfc2e784..70c6dad04 100644
--- a/json_tests/Cargo.toml
+++ b/json_tests/Cargo.toml
@@ -6,12 +6,12 @@ publish = false
[features]
trace-macros = []
+unstable-testing = ["compiletest_rs"]
-[dependencies]
+[dev-dependencies]
serde = "0.9.11"
serde_js... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-261 | 261 | [
"195"
] | 2017-02-21T06:11:59Z | a6effeece20e0fcca57540e295f21ee6294594ea | Implement Deserializer for &Value
We have an implementation of Deserializer for Value which consumes the Value - for example Value::String turns into visit_string. It would make sense to also implement Deserializer for &Value, so that for example &Value::String turns into visit_str.
| diff --git a/json/src/number.rs b/json/src/number.rs
index 97736432e..ff401d97e 100644
--- a/json/src/number.rs
+++ b/json/src/number.rs
@@ -180,6 +180,27 @@ impl Deserializer for Number {
}
}
+impl<'a> Deserializer for &'a Number {
+ type Error = Error;
+
+ #[inline]
+ fn deserialize<V>(self, visitor:... | diff --git a/json_tests/tests/test.rs b/json_tests/tests/test.rs
index 90f07d1c3..cea94c693 100644
--- a/json_tests/tests/test.rs
+++ b/json_tests/tests/test.rs
@@ -711,6 +711,10 @@ fn test_parse_ok<T>(tests: Vec<(&str, T)>)
let json_value: Value = from_str(s).unwrap();
assert_eq!(json_value, to_value... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-243 | 243 | [
"242"
] | 2017-02-04T00:40:16Z | Or `json!` should use ToJson instead of to_value. Would that work for your use case?
I think there is value in consistency across various Serde crates and part of that is `to_*` functions that take Serialize as input.
I think that sounds reasonable. For my specific use case, having `json!` use `ToJson` instead of `t... | 15827b445232d24f636d67c3178e2871aadaf5e5 | to_value should be bound on ToJson, not Serialize
All types that implement `Serialize` implement `ToJson`, but not all types that implement `ToJson` necessarily implement `Serialize`. So `to_value()` should be bound on `ToJson`, not `Serialize`, since that's all it really needs. That way I can implement `ToJson` on my ... | diff --git a/json/src/macros.rs b/json/src/macros.rs
index 8d5446b2f..71410dba0 100644
--- a/json/src/macros.rs
+++ b/json/src/macros.rs
@@ -254,6 +254,6 @@ macro_rules! json_internal {
// Any Serialize type: numbers, strings, struct literals, variables etc.
// Must be below every other rule.
($other:exp... | diff --git a/json_tests/tests/test.rs b/json_tests/tests/test.rs
index 5d7befcb3..90f07d1c3 100644
--- a/json_tests/tests/test.rs
+++ b/json_tests/tests/test.rs
@@ -28,6 +28,7 @@ use serde::bytes::{ByteBuf, Bytes};
use serde_json::{
Deserializer,
+ Error,
Value,
from_iter,
from_slice,
@@ -39,6... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-231 | 231 | [
"221"
] | 2017-01-29T16:05:17Z | We need to add a case for `Value::Number` inside `serde_json::value::SerializeMap::serialize_key`.
@killercup this is another quick one.
```rust
let mut map = BTreeMap::new();
map.insert(0, "x"); // integer key
serde_json::to_string(&map) // okay since https://github.com/serde-rs/json/pull/177
serde_json::to_v... | a9b695d36f85883b089f0f74c148e07c888f25d3 | Integer keys in to_value
The `to_string` function supports integer map keys but `to_value` does not.
| diff --git a/json/src/value.rs b/json/src/value.rs
index 074fb21be..aa420fdd0 100644
--- a/json/src/value.rs
+++ b/json/src/value.rs
@@ -1053,6 +1053,7 @@ impl ser::SerializeMap for SerializeMap {
{
match try!(to_value(&key)) {
Value::String(s) => self.next_key = Some(s),
+ Value::... | diff --git a/json_tests/tests/test.rs b/json_tests/tests/test.rs
index f06cfe86e..21bc91e02 100644
--- a/json_tests/tests/test.rs
+++ b/json_tests/tests/test.rs
@@ -665,6 +665,21 @@ fn test_write_newtype_struct() {
]);
}
+#[test]
+fn test_write_map_with_integer_keys_issue_221() {
+ let mut map = BTreeMap::ne... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-230 | 230 | [
"220",
"220"
] | 2017-01-29T15:42:55Z | The bug is that KeyOnlyVariantVisitor is parsing the string `"V"` inside visit_variant_seed and then parsing the number `0` inside visit_newtype_seed. The point of KeyOnlyVariantVisitor is that it is supposed to handle unit variants only so it should unconditionally return an error in all the VariantVisitor methods exc... | a9b695d36f85883b089f0f74c148e07c888f25d3 | Enums can parse invalid JSON
```rust
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[derive(Debug, Deserialize)]
enum E {
V(u8),
}
fn main() {
println!("{:?}", serde_json::from_str::<E>(r#" "V"0 "#));
}
```
```
Ok(V(0))
```
Enums can parse invalid JSON
```rust
#[macro_use... | diff --git a/json/src/de.rs b/json/src/de.rs
index 58a671987..ca66bcfd8 100644
--- a/json/src/de.rs
+++ b/json/src/de.rs
@@ -642,7 +642,7 @@ impl<'a, R: Read> de::Deserializer for &'a mut Deserializer<R> {
_ => Err(self.error(ErrorCode::ExpectedSomeValue)),
}
}
- ... | diff --git a/json_tests/tests/test.rs b/json_tests/tests/test.rs
index f06cfe86e..3c5e43eba 100644
--- a/json_tests/tests/test.rs
+++ b/json_tests/tests/test.rs
@@ -1133,6 +1133,8 @@ fn test_parse_enum_errors() {
"trailing characters at line 1 column 9"),
("\"Frog\"",
"EOF while parsi... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-210 | 210 | [
"151"
] | 2017-01-24T01:40:10Z | These need to be fixed:
- `serde_json::ser::Formatter`
- `serde_json::ser::escape_str`
- `serde_json::ser::to_string`
- `serde_json::ser::to_string_pretty`
- `serde_json::ser::to_vec`
- `serde_json::ser::to_vec_pretty`
- `serde_json::ser::to_writer`
- `serde_json::ser::to_writer_pretty` | b60dc2c7b766b07d8e1a82efdf6a728e1e9613d3 | Audit public API for missing ?Sized bounds
@withoutboats noticed that [`to_writer`](https://docs.serde.rs/serde_json/ser/fn.to_writer.html) could allow `T: ?Sized`, allowing something like `to_writer(w, "str")`.
| diff --git a/json/Cargo.toml b/json/Cargo.toml
index 20c21adaa..1cf45631c 100644
--- a/json/Cargo.toml
+++ b/json/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "serde_json"
-version = "0.9.0-rc1"
+version = "0.9.0-rc2"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description =... | diff --git a/json_tests/Cargo.toml b/json_tests/Cargo.toml
index f246e74cf..6d9544ffe 100644
--- a/json_tests/Cargo.toml
+++ b/json_tests/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "serde_json_tests"
-version = "0.9.0-rc1"
+version = "0.9.0-rc2"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
build = "bu... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-205 | 205 | [
"193"
] | 2017-01-21T19:23:13Z | You're right, this is not possible with the current serde_json API. We did some contortions when we introduced the DeserializeImpl-related optimizations (the separate specializations for &str vs &[u8] vs io::Read) to avoid breaking backward compatibility. I will try to rework some of this for 0.9.0 to make specializati... | 7a040fccab33df2a5a894dc378a77a18b9fdd317 | How to specialise on JSON deserialiser
Now that there's a non-public `DeserializerImpl` which is the one that's actually being used in `from_trait()`, it seems to have become impossible to use specialisation on JSON decoders when using the top-level `from_*()` methods.
E.g., I naively assumed something like this wou... | diff --git a/json/Cargo.toml b/json/Cargo.toml
index 28c62ba14..d9b1745f8 100644
--- a/json/Cargo.toml
+++ b/json/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "serde_json"
-version = "0.8.6"
+version = "0.9.0-rc1"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A ... | diff --git a/json_tests/Cargo.toml b/json_tests/Cargo.toml
index f3f6b45dc..e3b268954 100644
--- a/json_tests/Cargo.toml
+++ b/json_tests/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "serde_json_tests"
-version = "0.8.6"
+version = "0.9.0-rc1"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
build = "build.... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-197 | 197 | [
"196"
] | 2017-01-18T06:27:27Z | c7101a1d41f6f08a829fed10d649c2937292172d | Merge the old v0.9.0 branch into master
There is a branch from https://github.com/serde-rs/json/pull/143 that has unfortunately gotten pretty stale. We can merge it in now but it will take some work.
| diff --git a/json/src/ser.rs b/json/src/ser.rs
index 67d8df0bb..efc50baf5 100644
--- a/json/src/ser.rs
+++ b/json/src/ser.rs
@@ -75,81 +75,91 @@ impl<'a, W, F> ser::Serializer for &'a mut Serializer<W, F>
#[inline]
fn serialize_bool(self, value: bool) -> Result<()> {
- if value {
- self.wr... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index 0d4f6ac8c..982fcea07 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -1374,10 +1374,8 @@ fn test_serialize_seq_with_no_len() {
let s = serde_json::to_string_pretty(&vec).unwrap();
let expected = ... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-192 | 192 | [
"189"
] | 2017-01-16T03:16:27Z | 7550d401830b99791da4a2db36c7b1eec6cf5859 | Remove Value::lookup
This method is deprecated in favor of Value::pointer and pointer syntax.
| diff --git a/json/src/value.rs b/json/src/value.rs
index 3f28019e0..1400b9c1d 100644
--- a/json/src/value.rs
+++ b/json/src/value.rs
@@ -126,32 +126,6 @@ impl Value {
Some(target)
}
- /// **Deprecated**: Use `Value.pointer()` and pointer syntax instead.
- ///
- /// Looks up a value by path.
- ... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index f95755074..d0c0b2a85 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -1280,15 +1280,6 @@ fn test_find_path() {
assert!(obj.find_path(&["z"]).is_none());
}
-#[test]
-fn test_lookup() {
- let obj:... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-188 | 188 | [
"152",
"57"
] | 2017-01-15T22:29:30Z | We can avoid affecting types in the public API by replacing `serde_json::value::Map` (which is currently either `BTreeMap` or `LinkedHashMap`) with an opaque newtype wrapper around `BTreeMap` or `LinkedHashMap`. @oli-obk do you see a better approach?
| 016cfdbb86fc70e268db3b3c4cf707c6c44cb626 | Feature `preserve_order` is not additive
Cargo unions all features that all rdeps in a project of a crate want, and compiles the crate with that. This requires features to be additive. Since this feature changes the types used in the public API of the crate, it is not.
Unify the number variants in Value
I am not conv... | diff --git a/json/src/lib.rs b/json/src/lib.rs
index 83a3644f2..1e6e540f3 100644
--- a/json/src/lib.rs
+++ b/json/src/lib.rs
@@ -102,7 +102,7 @@
//!
//! for (key, value) in obj.iter() {
//! println!("{}: {}", key, match *value {
-//! Value::U64(v) => format!("{} (u64)", v),
+//! V... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index 442e03ede..783d8365a 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -1,3 +1,4 @@
+use std::collections::BTreeMap;
use std::f64;
use std::fmt::Debug;
use std::i64;
@@ -24,13 +25,30 @@ use serde_json::{
... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-187 | 187 | [
"186"
] | 2017-01-15T18:48:26Z | This applies to ToJson::to_json as well. | d8cf0146aa7f633ff7169aa6d0b438ce7ba990a0 | Return Result<Value, Error> from to_value
Currently `to_value` returns Value and panics if the conversion fails.
| diff --git a/json/src/builder.rs b/json/src/builder.rs
index 0765dd84b..76d0d4e2e 100644
--- a/json/src/builder.rs
+++ b/json/src/builder.rs
@@ -55,8 +55,12 @@ impl ArrayBuilder {
}
/// Insert a value into the array.
+ ///
+ /// This method panics if the value cannot be represented as JSON. This can
+... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index f95755074..851b732b2 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -66,7 +66,7 @@ fn test_encode_ok<T>(errors: &[(T, &str)])
let s = serde_json::to_string(value).unwrap();
assert_eq!(s,... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-159 | 159 | [
"157"
] | 2016-10-04T04:29:18Z | b35c3c7202dbaf107730928dd32915727cbe80be | Update tests to use serde_derive
The Travis build is failing because serde_macros no longer compiles.
| diff --git a/build.rs b/build.rs
deleted file mode 100644
index b1aadd789..000000000
--- a/build.rs
+++ /dev/null
@@ -1,29 +0,0 @@
-#[cfg(not(feature = "serde_macros"))]
-mod inner {
- extern crate syntex;
- extern crate serde_codegen;
-
- use std::env;
- use std::path::Path;
-
- pub fn main() {
- ... | diff --git a/json_tests/Cargo.toml b/json_tests/Cargo.toml
index b477d9bc7..6e44adf8f 100644
--- a/json_tests/Cargo.toml
+++ b/json_tests/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
build = "build.rs"
[features]
-default = ["serde_macros"]
+default = ["serde_derive"]
with-s... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-156 | 156 | [
"155"
] | 2016-09-25T19:33:26Z | I can look into this.
Looks like serializing `Value::F64(_)` simply proxies to `serialize_f64(v)`, where it should really check for `FpCategory::{Nan, Infinite}`, as serialization only works for finite values (https://tc39.github.io/ecma262/#sec-serializejsonproperty).
| b4022a299a4664e6bd983471b4519c6353352a23 | to_value(NAN) should be null
``` rust
extern crate serde_json;
fn main() {
let value = serde_json::to_value(::std::f64::NAN);
println!("value: {}", value);
println!("value.is_null(): {}", value.is_null());
}
```
Expected:
```
value: null
value.is_null(): true
```
Actual:
```
value: null
value.is_null()... | diff --git a/json/src/value.rs b/json/src/value.rs
index ce6d9b5fe..d46f7b735 100644
--- a/json/src/value.rs
+++ b/json/src/value.rs
@@ -643,7 +643,11 @@ impl ser::Serializer for Serializer {
#[inline]
fn serialize_f64(&mut self, value: f64) -> Result<(), Error> {
- self.value = Value::F64(value);
+ ... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index 7d7391701..0c8337a4b 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -132,6 +132,21 @@ fn test_write_f64() {
test_pretty_encode_ok(tests);
}
+#[test]
+fn test_encode_nonfinite_float_yields_null() {... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-143 | 143 | [
"142"
] | 2016-08-25T21:56:26Z | I think this is a good idea as long as it does not affect performance when using CompactFormatter because people tend to care about that. Of the functions you suggested, I think we can make all of those work efficiently except `fn string(...)` because it would require heap-allocating the entire escaped string even in c... | 146cf17f78c0a86801b10f0250e86d1078d5f450 | Expand Formatter support
I want to offer pretty printing of JSON objects beyond what the `PrettyFormatter` can supply, for example color support or intelligent line wrapping. For that, I'd like to expose more callbacks to control formatting.
Ideally I would like to be able to color every "token type" differently.
Cu... | diff --git a/json/src/ser.rs b/json/src/ser.rs
index c81bff269..c758581d8 100644
--- a/json/src/ser.rs
+++ b/json/src/ser.rs
@@ -10,6 +10,7 @@ use super::error::{Error, ErrorCode, Result};
use itoa;
use dtoa;
+use num_traits;
/// A structure for serializing Rust values into JSON.
pub struct Serializer<W, F = Co... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index 7d7391701..56c7071c4 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -1350,10 +1350,8 @@ fn test_serialize_seq_with_no_len() {
let s = serde_json::to_string_pretty(&vec).unwrap();
let expected = ... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-115 | 115 | [
"77"
] | 2016-07-12T05:07:26Z | 4cc85e55f61e6220b587854209b0d587f2ba1bab | Unexpected brackets in to_value of a newtype struct
``` rust
#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]
use std::collections::BTreeMap;
extern crate serde_json;
#[derive(Serialize, Deserialize)]
struct Bar(BTreeMap<String, i32>);
fn main() {
let mut b = Bar(BTreeMap::new());
b.0.insert(Stri... | diff --git a/json/src/value.rs b/json/src/value.rs
index f31962db4..af7057850 100644
--- a/json/src/value.rs
+++ b/json/src/value.rs
@@ -611,6 +611,15 @@ impl ser::Serializer for Serializer {
self.serialize_str(variant)
}
+ #[inline]
+ fn serialize_newtype_struct<T>(&mut self,
+ ... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index 6a9442e75..b91691451 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -644,6 +644,23 @@ fn test_write_option() {
]);
}
+#[test]
+fn test_write_newtype_struct() {
+ #[derive(Serialize, PartialEq, ... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-114 | 114 | [
"112"
] | 2016-07-11T18:37:28Z | 4cc85e55f61e6220b587854209b0d587f2ba1bab | Error on large numbers instead of parsing infinity
Not only does it break round tripping, it's also very confusing to get an infinity from a non-infinite number.
| diff --git a/json/src/de.rs b/json/src/de.rs
index a6dec2420..c296675fc 100644
--- a/json/src/de.rs
+++ b/json/src/de.rs
@@ -404,12 +404,7 @@ impl<R: Read> DeserializerImpl<R> {
let digit = (c - b'0') as i32;
if overflow!(exp * 10 + digit, i32::MAX) {
- // Really big exponent,... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index 6a9442e75..3bc52eac5 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -771,6 +771,29 @@ fn test_parse_number_errors() {
("1e", Error::Syntax(ErrorCode::InvalidNumber, 1, 2)),
("1e+", Error... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-111 | 111 | [
"103"
] | 2016-07-11T07:52:56Z | e059d03aea557bbd2c53ff5af18951c65da8f509 | Rename feature "nightly-testing" to "unstable-testing"
See https://github.com/serde-rs/serde/issues/404.
> From what I understand, the community has started to use the feature `unstable*` instead of `nightly*` for things that may depend on the nightly compiler. If this is the case, when we do 0.8, we should consider r... | diff --git a/.travis.yml b/.travis.yml
index f910ad7b1..d567d1127 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,7 +32,7 @@ script:
(cd json && travis-cargo build) &&
(cd json && travis-cargo --only nightly test) &&
(cd json_tests && travis-cargo --skip nightly test -- --features with-synt... | diff --git a/json_tests/Cargo.toml b/json_tests/Cargo.toml
index 8775683db..facb98908 100644
--- a/json_tests/Cargo.toml
+++ b/json_tests/Cargo.toml
@@ -7,7 +7,7 @@ build = "build.rs"
[features]
default = ["serde_macros"]
with-syntex = ["syntex", "serde_codegen", "indoc/with-syntex"]
-nightly-testing = ["clippy", "s... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-110 | 110 | [
"108",
"109"
] | 2016-07-11T07:40:17Z | e059d03aea557bbd2c53ff5af18951c65da8f509 | Parsing floats is slow
These two lines are extremely expensive:

We can entirely avoid the division and multiplication by using a lookup table, or some other better approach.
Long integer causes the ... | diff --git a/json/src/de.rs b/json/src/de.rs
index ab3e3e3a2..dece310d3 100644
--- a/json/src/de.rs
+++ b/json/src/de.rs
@@ -2,9 +2,8 @@
//!
//! This module provides for JSON deserialization with the type `Deserializer`.
-use std::i32;
+use std::{f64, i32, i64, u64};
use std::io;
-use std::str;
use std::marker::P... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index 391b97452..6faaaa12d 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -750,11 +750,14 @@ fn test_parse_number_errors() {
(".", Error::Syntax(ErrorCode::ExpectedSomeValue, 1, 1)),
("-", Err... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd | |
null | serde-rs__json-93 | 93 | [
"53"
] | 2016-07-03T16:48:14Z | I'd suggest `build` as the new name because it's shorter than `to_value` while being at least as clear.
:+1: for `build`. Same thing for ArrayBuilder.
+1 to `build`, especially since it's a builder.
| 12f617d966e2169bfe90bb26397bc1ea7c124501 | ObjectBuilder: Rename unwrap?
Correct me if I'm wrong, but `ObjectBuilder::unwrap` doesn't actually `panic!()`, right? If so, I think it should be renamed to `to_value` or something like that.
| diff --git a/json/src/builder.rs b/json/src/builder.rs
index 142a3e458..8a00b7222 100644
--- a/json/src/builder.rs
+++ b/json/src/builder.rs
@@ -30,7 +30,7 @@
//! builder.insert("x", 3).insert("y", 4)
//! })
//! })
-//! .unwrap();
+//! .build();
//! ```
use serde::ser;
@@ ... | diff --git a/json_tests/tests/test_json_builder.rs b/json_tests/tests/test_json_builder.rs
index 948aa511e..189b0d3a3 100644
--- a/json_tests/tests/test_json_builder.rs
+++ b/json_tests/tests/test_json_builder.rs
@@ -4,19 +4,19 @@ use serde_json::builder::{ArrayBuilder, ObjectBuilder};
#[test]
fn test_array_builder... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-85 | 85 | [
"65",
"51"
] | 2016-06-25T21:51:25Z |
A PR would be appreciated!
| 4ef396bf6af251ae835c22db78bc08fca91c8dd6 | Correctly escape ASCII control characters in strings
This patch escapes ASCII control characters in the range 0x00...0x1f, in accordance with the JSON spec.
Fixes #51
Need to escape ASCII control characters
Serializing control characters such as `"\x01"` results in these characters being passed through, ie `"\"\x01\"... | diff --git a/json/src/ser.rs b/json/src/ser.rs
index e2d4479e2..bbac3cf74 100644
--- a/json/src/ser.rs
+++ b/json/src/ser.rs
@@ -504,6 +504,7 @@ pub fn escape_bytes<W>(wr: &mut W, bytes: &[u8]) -> Result<()>
b'\n' => b"\\n",
b'\r' => b"\\r",
b'\t' => b"\\t",
+ b'\x00' .... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index faf2f8d7f..f67a3eef2 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -461,7 +461,7 @@ fn test_write_object() {
let complex_obj = Value::Object(treemap!(
"b".to_string() => Value::Array(vec!... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-41 | 41 | [
"9"
] | 2016-02-27T15:14:29Z | A belated sure! That would be awesome!
| 7bc9b0a98ec65b90f8c4600d5966d1ca0679b089 | Consider using JSON pointers
JSON values provide a convenience to look up nested values called [`Value.lookup`](http://serde-rs.github.io/json/serde_json/value/enum.Value.html#method.lookup). The path is given separated by dots. It is impossible to escape dots in key names with the current method. I propose to use JSON... | diff --git a/json/Cargo.toml b/json/Cargo.toml
index 3c4765c52..0a82dc7c4 100644
--- a/json/Cargo.toml
+++ b/json/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "serde_json"
-version = "0.7.0"
+version = "0.7.1"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A JSON... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index fa765fd98..716b7195b 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -1447,3 +1447,40 @@ fn test_json_stream_empty() {
assert!(parsed.next().is_none());
}
+
+#[test]
+fn test_json_pointer() {
+ ... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
null | serde-rs__json-31 | 31 | [
"30"
] | 2016-01-23T12:59:26Z | b7a6592d8cb76c2eeef6e25c8f7b374883a0edbc | Missing () field in a struct is not reported as an error
If a `()` struct field is missing when deserializing JSON input, no error is reported. This means there's no distinction between `()` and `Option<()>`.
This is related to issue #29, which is about missing `Vec<_>` fields going unreported, and issue #22, which is... | diff --git a/json/src/de.rs b/json/src/de.rs
index 7b9bc8e60..02b22c22b 100644
--- a/json/src/de.rs
+++ b/json/src/de.rs
@@ -745,10 +745,31 @@ impl<'a, Iter> de::MapVisitor for MapVisitor<'a, Iter>
}
}
- fn missing_field<V>(&mut self, _field: &'static str) -> Result<V>
+ fn missing_field<V>(&mut s... | diff --git a/json_tests/tests/test_json.rs b/json_tests/tests/test_json.rs
index d5ad4c9a9..dd4e85762 100644
--- a/json_tests/tests/test_json.rs
+++ b/json_tests/tests/test_json.rs
@@ -911,6 +911,8 @@ fn test_parse_struct() {
("5", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 1)),
("\"hello\"",... | serde-rs/json | d37fc6cc7e94238c4f533560061aa768f1f2b8fd |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.