Skip to content

Commit d3182d9

Browse files
committed
Update serde support
1 parent 405d8df commit d3182d9

File tree

8 files changed

+40
-39
lines changed

8 files changed

+40
-39
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ before_script:
1010
- "./.travis/setup.sh"
1111
script:
1212
- cargo test
13-
- cargo test --features "uuid rustc-serialize time unix_socket serde chrono openssl"
13+
- cargo test --features "uuid rustc-serialize time unix_socket serde_json chrono openssl"

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ rustc-serialize = "0.3"
3232
net2 = { version = "0.2", features = ["nightly"] }
3333
chrono = { version = "0.2.14", optional = true }
3434
openssl = { version = "0.6.4", optional = true }
35-
serde = { version = "0.3", optional = true }
35+
serde_json = { version = "0.6", optional = true }
3636
time = { version = "0.1.14", optional = true }
3737
unix_socket = { version = ">= 0.3, < 0.5", optional = true, features = ["socket_timeout"] }
3838
uuid = { version = "0.1", optional = true }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ types. The driver currently supports the following conversions:
200200
<td>
201201
<a href="https://github.com/rust-lang/rustc-serialize">serialize::json::Json</a>
202202
and
203-
<a href="https://github.com/erickt/serde">serde::json::Value</a>
203+
<a href="https://github.com/erickt/serde_json">serde_json::Value</a>
204204
(<a href="#optional-features">optional</a>)
205205
</td>
206206
<td>JSON, JSONB</td>
@@ -284,7 +284,7 @@ implementations for `uuid`'s `Uuid` type.
284284
[JSON and JSONB](http://www.postgresql.org/docs/9.4/static/datatype-json.html)
285285
support is provided optionally by the `rustc-serialize` feature, which adds
286286
`ToSql` and `FromSql` implementations for `rustc-serialize`'s `Json` type, and
287-
the `serde` feature, which adds implementations for `serde`'s `json::Value`
287+
the `serde` feature, which adds implementations for `serde_json`'s `Value`
288288
type.
289289

290290
### TIMESTAMP/TIMESTAMPTZ/DATE/TIME types

src/types/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ mod time;
4949
mod slice;
5050
#[cfg(feature = "rustc-serialize")]
5151
mod rustc_serialize;
52-
#[cfg(feature = "serde")]
53-
mod serde;
52+
#[cfg(feature = "serde_json")]
53+
mod serde_json;
5454
#[cfg(feature = "chrono")]
5555
mod chrono;
5656

@@ -571,13 +571,13 @@ impl error::Error for WasNull {
571571
/// In addition, some implementations are provided for types in third party
572572
/// crates. These are disabled by default; to opt into one of these
573573
/// implementations, activate the Cargo feature corresponding to the crate's
574-
/// name. For example, the `serde` feature enables the implementation for the
575-
/// `serde::json::Value` type.
574+
/// name. For example, the `serde_json` feature enables the implementation for
575+
/// the `serde_json::Value` type.
576576
///
577577
/// | Rust type | Postgres type(s) |
578578
/// |-------------------------------------|-------------------------------------|
579579
/// | serialize::json::Json | JSON, JSONB |
580-
/// | serde::json::Value | JSON, JSONB |
580+
/// | serde_json::Value | JSON, JSONB |
581581
/// | time::Timespec | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
582582
/// | chrono::NaiveDateTime | TIMESTAMP |
583583
/// | chrono::DateTime&lt;UTC&gt; | TIMESTAMP WITH TIME ZONE |
@@ -616,6 +616,7 @@ pub trait FromSql: Sized {
616616
///
617617
/// The default implementation returns
618618
/// `Err(Error::Conversion(Box::new(WasNull))`.
619+
#[allow(unused_variables)]
619620
fn from_sql_null(ty: &Type, ctx: &SessionInfo) -> Result<Self> {
620621
Err(Error::Conversion(Box::new(WasNull)))
621622
}
@@ -776,13 +777,13 @@ pub enum IsNull {
776777
/// In addition, some implementations are provided for types in third party
777778
/// crates. These are disabled by default; to opt into one of these
778779
/// implementations, activate the Cargo feature corresponding to the crate's
779-
/// name. For example, the `serde` feature enables the implementation for the
780-
/// `serde::json::Value` type.
780+
/// name. For example, the `serde_json` feature enables the implementation for
781+
/// the `serde_json::Value` type.
781782
///
782783
/// | Rust type | Postgres type(s) |
783784
/// |-------------------------------------|-------------------------------------|
784785
/// | serialize::json::Json | JSON, JSONB |
785-
/// | serde::json::Value | JSON, JSONB |
786+
/// | serde_json::Value | JSON, JSONB |
786787
/// | time::Timespec | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
787788
/// | chrono::NaiveDateTime | TIMESTAMP |
788789
/// | chrono::DateTime&lt;UTC&gt; | TIMESTAMP WITH TIME ZONE |

src/types/serde.rs renamed to src/types/serde_json.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
extern crate serde;
1+
extern crate serde_json;
22

33
use std::error;
44
use std::io::prelude::*;
55
use byteorder::{ReadBytesExt, WriteBytesExt};
6-
use self::serde::json::{self, Value};
6+
use self::serde_json::Value;
77

88
use Result;
99
use error::Error;
@@ -18,7 +18,7 @@ impl FromSql for Value {
1818
return Err(Error::Conversion(err));
1919
}
2020
}
21-
json::de::from_reader(raw).map_err(|err| Error::Conversion(Box::new(err)))
21+
serde_json::de::from_reader(raw).map_err(|err| Error::Conversion(Box::new(err)))
2222
}
2323

2424
accepts!(Type::Json, Type::Jsonb);

tests/types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ mod uuid;
1313
mod time;
1414
#[cfg(feature = "rustc-serialize")]
1515
mod rustc_serialize;
16-
#[cfg(feature = "serde")]
17-
mod serde;
16+
#[cfg(feature = "serde_json")]
17+
mod serde_json;
1818
#[cfg(feature = "chrono")]
1919
mod chrono;
2020

tests/types/serde.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/types/serde_json.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extern crate serde_json;
2+
3+
use self::serde_json::Value;
4+
use types::test_type;
5+
6+
#[test]
7+
fn test_json_params() {
8+
test_type("JSON", &[(Some(serde_json::from_str::<Value>("[10, 11, 12]").unwrap()),
9+
"'[10, 11, 12]'"),
10+
(Some(serde_json::from_str::<Value>("{\"f\": \"asd\"}").unwrap()),
11+
"'{\"f\": \"asd\"}'"),
12+
(None, "NULL")])
13+
}
14+
15+
#[test]
16+
fn test_jsonb_params() {
17+
test_type("JSONB", &[(Some(serde_json::from_str::<Value>("[10, 11, 12]").unwrap()),
18+
"'[10, 11, 12]'"),
19+
(Some(serde_json::from_str::<Value>("{\"f\": \"asd\"}").unwrap()),
20+
"'{\"f\": \"asd\"}'"),
21+
(None, "NULL")])
22+
}

0 commit comments

Comments
 (0)