Skip to content

Commit

Permalink
Merge pull request #309 from japplegame/bugfix
Browse files Browse the repository at this point in the history
fix deserializeJson/Bson
  • Loading branch information
s-ludwig committed Sep 19, 2013
2 parents 35d7992 + d1e6b84 commit 2bba2bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions source/vibe/data/bson.d
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ struct Bson {
}

/** Converts a BSON value to a JSON value.
All BSON types that cannot be exactly represented as JSON, will
be converted to a string.
*/
Expand Down Expand Up @@ -979,11 +979,11 @@ T deserializeBson(T)(Bson src)
foreach( string key, value; cast(Bson[string])src )
dst[key] = deserializeBson!(Unqual!TV)(value);
return dst;
} else static if (is(typeof(value.toBson()) == Bson) && is(typeof(T.fromBson(Bson())) == T)) {
} else static if (is(typeof(T.fromBson(Bson()).toBson()) == Bson) && is(typeof(T.fromBson(Bson())) == T)) {
return T.fromBson(src);
} else static if (is(typeof(value.toJson()) == Json) && is(typeof(T.fromJson(Json())) == T)) {
} else static if (is(typeof(T.fromJson(Json()).toJson()) == Json) && is(typeof(T.fromJson(Json())) == T)) {
return T.fromJson(src.toJson());
} else static if (is(typeof(value.toString()) == string) && is(typeof(T.fromString("")) == T)) {
} else static if (is(typeof(T.fromString("").toString()) == string) && is(typeof(T.fromString("")) == T)) {
return T.fromString(cast(string)src);
} else static if (is(T == struct)) {
T dst;
Expand Down Expand Up @@ -1090,7 +1090,7 @@ private Bson.Type writeBson(R)(ref R dst, in Json value)
Bson.Type.Array,
Bson.Type.Object
];

final switch(value.type){
case Json.Type.Undefined:
return Bson.Type.Undefined;
Expand Down Expand Up @@ -1146,10 +1146,10 @@ unittest
{
Json jsvalue = parseJsonString("{\"key\" : \"Value\"}");
assert(serializeToBson(jsvalue).toJson() == jsvalue);

jsvalue = parseJsonString("{\"key\" : [{\"key\" : \"Value\"}, {\"key2\" : \"Value2\"}] }");
assert(serializeToBson(jsvalue).toJson() == jsvalue);

jsvalue = parseJsonString("[ 1 , 2 , 3]");
assert(serializeToBson(jsvalue).toJson() == jsvalue);
}
Expand Down
4 changes: 2 additions & 2 deletions source/vibe/data/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,9 @@ T deserializeJson(T)(Json src)
foreach( string key, value; src )
dst[key] = deserializeJson!(Unqual!TV)(value);
return dst;
} else static if (is(typeof(value.toJson()) == Json) && is(typeof(T.fromJson(Json())) == T)) {
} else static if (is(typeof(T.fromJson(Json()).toJson()) == Json) && is(typeof(T.fromJson(Json())) == T)) {
return T.fromJson(src);
} else static if (is(typeof(value.toString()) == string) && is(typeof(T.fromString("")) == T)) {
} else static if (is(typeof(T.fromString("").toString()) == string) && is(typeof(T.fromString("")) == T)) {
return T.fromString(src.get!string);
} else static if( is(T == struct) ){
T dst;
Expand Down

0 comments on commit 2bba2bc

Please sign in to comment.