You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement Serialize without going through JsonObject (#233)
* Implement `Serialize` without going through JsonObject
As described in <#152>,
serialization by constructing a JsonObject has to essentially clone all
data, which requires extra allocations.
After this change, we pass data directly to the `Serializer`.
`JsonObject` and `JsonValue` conversion impls were rewritten to delegate
to `Serialize`. This requires some unfortunate `panic`s where we expect
`Serialize` to produce a JSON object, but I think it's better than
duplicating the serialization logic.
* Serialize None properties as null
* Add comments around to_value unwraps and panics
let feature_json_str = "{\"geometry\":{\"coordinates\":[1.1,2.1],\"type\":\"Point\"},\"id\":0,\"properties\":{},\"type\":\"Feature\"}";
342
+
let feature_json_str = "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.1,2.1]},\"properties\":{},\"id\":0}";
348
343
let feature = crate::Feature{
349
344
geometry:Some(Geometry{
350
345
value:Value::Point(vec![1.1,2.1]),
@@ -370,7 +365,7 @@ mod tests {
370
365
371
366
#[test]
372
367
fnencode_decode_feature_with_id_string(){
373
-
let feature_json_str = "{\"geometry\":{\"coordinates\":[1.1,2.1],\"type\":\"Point\"},\"id\":\"foo\",\"properties\":{},\"type\":\"Feature\"}";
368
+
let feature_json_str = "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.1,2.1]},\"properties\":{},\"id\":\"foo\"}";
374
369
let feature = crate::Feature{
375
370
geometry:Some(Geometry{
376
371
value:Value::Point(vec![1.1,2.1]),
@@ -416,7 +411,8 @@ mod tests {
416
411
fnencode_decode_feature_with_foreign_member(){
417
412
usecrate::JsonObject;
418
413
use serde_json;
419
-
let feature_json_str = "{\"geometry\":{\"coordinates\":[1.1,2.1],\"type\":\"Point\"},\"other_member\":\"some_value\",\"properties\":{},\"type\":\"Feature\"}";
414
+
let feature_json_str = "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.1,2.1]},\"properties\":{},\"other_member\":\"some_value\"}";
415
+
420
416
letmut foreign_members = JsonObject::new();
421
417
foreign_members.insert(
422
418
String::from("other_member"),
@@ -445,6 +441,29 @@ mod tests {
445
441
assert_eq!(decoded_feature, feature);
446
442
}
447
443
444
+
#[test]
445
+
fnencode_decode_feature_with_null_properties(){
446
+
let feature_json_str = r#"{"type":"Feature","geometry":{"type":"Point","coordinates":[1.1,2.1]},"properties":null}"#;
0 commit comments