<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>Libraries/GTM/YAJL_GTMBase64.h</filename>
    </added>
    <added>
      <filename>Libraries/GTM/YAJL_GTMBase64.m</filename>
    </added>
    <added>
      <filename>Tests/Samples/gen_expected_ignore_unknown1.json</filename>
    </added>
    <added>
      <filename>Tests/Samples/gen_expected_plist1.json</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -38,12 +38,30 @@ extern NSString *const YAJLGenInvalidObjectException;
 enum {
 	YAJLGenOptionsNone = 0,	
 	YAJLGenOptionsBeautify = 1 &lt;&lt; 0,
+  YAJLGenOptionsIgnoreUnknownTypes = 1 &lt;&lt; 1, // Ignore unknown types (will use null value)
+  YAJLGenOptionsIncludeUnsupportedTypes = 1 &lt;&lt; 2, // Handle non-JSON types (including NSDate, NSData, NSURL)
 };
 typedef NSUInteger YAJLGenOptions;
 
-
+/*!
+ YAJL JSON string generator.
+ Supports the following types:
+ - NSArray
+ - NSDictionary
+ - NSString
+ - NSNumber
+ - NSNull
+ 
+ We also support the following types (if using YAJLGenOptionsIncludeUnsupportedTypes option),
+ by converting to JSON supported types:
+ - NSDate -&gt; number representing number of milliseconds since (1970) epoch
+ - NSData -&gt; Base64 encoded string
+ - NSURL -&gt; URL (absolute) string 
+ */
 @interface YAJLGen : NSObject {
 	yajl_gen gen_;
+  
+  YAJLGenOptions genOptions_;
 }
 
 - (id)initWithGenOptions:(YAJLGenOptions)genOptions indentString:(NSString *)indentString;</diff>
      <filename>Classes/YAJLGen.h</filename>
    </modified>
    <modified>
      <diff>@@ -28,6 +28,7 @@
 //
 
 #import &quot;YAJLGen.h&quot;
+#import &quot;YAJL_GTMBase64.h&quot;
 
 NSString *const YAJLGenInvalidObjectException = @&quot;YAJLGenInvalidObjectException&quot;;
 
@@ -39,6 +40,7 @@ NSString *const YAJLGenInvalidObjectException = @&quot;YAJLGenInvalidObjectException&quot;
 
 - (id)initWithGenOptions:(YAJLGenOptions)genOptions indentString:(NSString *)indentString {
 	if ((self = [super init])) {
+    genOptions_ = genOptions;
 		yajl_gen_config cfg = { 
 			((genOptions &amp; YAJLGenOptionsBeautify) ? 1 : 0),
 			[indentString UTF8String]
@@ -78,8 +80,32 @@ NSString *const YAJLGenInvalidObjectException = @&quot;YAJLGenInvalidObjectException&quot;
 		[self string:obj];
 	} else if ([obj isKindOfClass:[NSNull class]]) {
 		[self null];
-	} else {
-		[NSException raise:YAJLGenInvalidObjectException format:@&quot;Invalid object: %@&quot;, obj];
+	} else {    
+    
+    BOOL unknownType = NO;
+    if (genOptions_ &amp; YAJLGenOptionsIncludeUnsupportedTypes) {
+      // Begin with support for non-JSON representable (PList) types
+      if ([obj isKindOfClass:[NSDate class]]) { 
+        [self number:[NSNumber numberWithLongLong:round([obj timeIntervalSince1970] * 1000)]];
+      } else if ([obj isKindOfClass:[NSData class]]) {
+        [self string:[YAJL_GTMBase64 stringByEncodingData:obj]];
+      } else if ([obj isKindOfClass:[NSURL class]]) {
+        [self string:[obj absoluteString]];
+      } else {
+        unknownType = YES;
+      }
+    } else {
+      unknownType = YES;
+    }
+    
+    // If we didn't handle special PList types
+    if (unknownType) {
+      if (!(genOptions_ &amp; YAJLGenOptionsIgnoreUnknownTypes)) {
+        [NSException raise:YAJLGenInvalidObjectException format:@&quot;Unknown object type: %@ (%@)&quot;, [obj class], obj];
+      } else {
+        [self null]; // Use null value for unknown type if we are ignoring
+      }
+    }
 	}
 }
 
@@ -133,3 +159,7 @@ NSString *const YAJLGenInvalidObjectException = @&quot;YAJLGenInvalidObjectException&quot;
 }	
 
 @end
+
+
+
+</diff>
      <filename>Classes/YAJLGen.m</filename>
    </modified>
    <modified>
      <diff>@@ -76,4 +76,42 @@
 	GHAssertEqualStrings(buffer, expected, nil);	
 }
 
+- (void)testGenObjectUnknownType {
+  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSDate dateWithTimeIntervalSince1970:1], @&quot;date&quot;, nil];  
+  YAJLGen *gen = [[YAJLGen alloc] init];
+	GHAssertThrows([gen object:dict], nil);
+	[gen release];
+}
+
+- (void)testGenObjectIgnoreUnknownType {
+  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSDate dateWithTimeIntervalSince1970:1], @&quot;date&quot;, nil];
+  
+  YAJLGen *gen = [[YAJLGen alloc] initWithGenOptions:YAJLGenOptionsIgnoreUnknownTypes indentString:@&quot;&quot;];
+	[gen object:dict];
+	NSString *buffer = [gen buffer];
+	[gen release];
+	
+	NSString *expected = [self loadString:@&quot;gen_expected_ignore_unknown1&quot;];	
+	GHTestLog(buffer);
+	GHAssertEqualStrings(buffer, expected, nil);	
+}
+
+- (void)testGenObjectPListTypes {
+  const char *testData = &quot;ABCDEFG&quot;;
+  NSArray *array = [NSArray arrayWithObjects:
+                    [NSDate dateWithTimeIntervalSince1970:1], 
+                    [NSData dataWithBytes:testData length:6],
+                    [NSURL URLWithString:@&quot;http://www.yelp.com/&quot;],
+                    nil];
+  
+  YAJLGen *gen = [[YAJLGen alloc] initWithGenOptions:YAJLGenOptionsIncludeUnsupportedTypes indentString:@&quot;&quot;];
+	[gen object:array];
+	NSString *buffer = [gen buffer];
+	[gen release];
+	
+	NSString *expected = [self loadString:@&quot;gen_expected_plist1&quot;];	
+	GHTestLog(buffer);
+	GHAssertEqualStrings(buffer, expected, nil);	
+}
+
 @end</diff>
      <filename>Tests/YAJLGenTest.m</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>34515ffd3017a45a6308c5884a4f8a127d52bd31</id>
    </parent>
  </parents>
  <author>
    <name>Gabriel Handford</name>
    <email>gabrielh@gmail.com</email>
  </author>
  <url>http://github.com/gabriel/yajl-objc/commit/df6742e1594b40f47aba20aa55aac935f2062b84</url>
  <id>df6742e1594b40f47aba20aa55aac935f2062b84</id>
  <committed-date>2009-10-30T11:31:51-07:00</committed-date>
  <authored-date>2009-10-30T11:31:51-07:00</authored-date>
  <message>Adding options to support unsupported types</message>
  <tree>b3738e60856dfc30420b4909932f688f004e4689</tree>
  <committer>
    <name>Gabriel Handford</name>
    <email>gabrielh@gmail.com</email>
  </committer>
</commit>
