Permalink
Browse files

fixed serialization of nulls.

Previously we were incorrectly serializing nulls as strings.
  • Loading branch information...
1 parent 3b1c40c commit 82b6cc62cb0149f96a69f5772a9715f8a41e7cd7 Tim Burks committed Nov 24, 2010
Showing with 8 additions and 6 deletions.
  1. +3 −4 objc/NuBSON.m
  2. +5 −2 test/test_bson.nu
View
@@ -83,7 +83,6 @@ - (NSData *) data
void add_object_to_bson_buffer(bson_buffer *bb, id key, id object)
{
const char *name = [key cStringUsingEncoding:NSUTF8StringEncoding];
-
Class NuCell = NSClassFromString(@"NuCell");
Class NuSymbol = NSClassFromString(@"NuSymbol");
@@ -116,9 +115,6 @@ void add_object_to_bson_buffer(bson_buffer *bb, id key, id object)
break;
}
}
- else if ([object respondsToSelector:@selector(cStringUsingEncoding:)]) {
- bson_append_string(bb, name,[object cStringUsingEncoding:NSUTF8StringEncoding]);
- }
else if ([object isKindOfClass:[NSDictionary class]]) {
bson_buffer *sub = bson_append_start_object(bb, name);
id keys = [object allKeys];
@@ -174,6 +170,9 @@ void add_object_to_bson_buffer(bson_buffer *bb, id key, id object)
bson_append_finish_object(arr);
}
}
+ else if ([object respondsToSelector:@selector(cStringUsingEncoding:)]) {
+ bson_append_string(bb, name,[object cStringUsingEncoding:NSUTF8StringEncoding]);
+ }
else {
NSLog(@"We have a problem. %@ cannot be serialized to bson", object);
}
View
@@ -14,7 +14,8 @@
d:(NSDate date)
e:123.456
f:(dict a:(array 1 2 3))
- g:(NSData dataWithContentsOfFile:"mongoleaf.png")))
+ g:(NSData dataWithContentsOfFile:"mongoleaf.png")
+ h:nil))
(set data (x BSONRepresentation))
(set y (data BSONValue))
(assert_equal (x a:) (y a:))
@@ -27,6 +28,7 @@
(assert_equal (x e:) (y e:))
(assert_equal (x f:) (y f:))
(assert_equal (x g:) (y g:))
+ (assert_equal (x h:) (y h:))
(set data (y BSONRepresentation))
(set z (data BSONValue))
@@ -37,4 +39,5 @@
(assert_equal (y d:) (z d:))
(assert_equal (y e:) (z e:))
(assert_equal (y f:) (z f:))
- (assert_equal (y g:) (z g:))))
+ (assert_equal (y g:) (z g:))
+ (assert_equal (y h:) (z h:))))

0 comments on commit 82b6cc6

Please sign in to comment.