Repository: gcanti/tcomb (js)

Issue:
null Maybes stringify to {}
Hello, something changed between 3.2.4 and 3.2.5 that causes this undesirable behavior

### Expected behaviour

```
const thing = t.struct({ foo: t.maybe(t.struct({ bar: t.String })) })
> JSON.stringify(thing({foo: null}))
'{"foo":null}'
```

### Actual behaviour

```
> JSON.stringify(thing({foo: null}))
'{"foo":{}}'
```


Pull request:
null Maybes should stringify to null, fix #227

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cbaf09b..c6ab378 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,11 @@
 **Note**: Gaps between patch versions are faulty/broken releases.
 **Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.
 
+# v3.2.6
+
+- **Bug Fix**
+  - null Maybes should stringify to null, fix #227 (@gcanti)
+
 # v3.2.5
 
 - **Polish**
diff --git a/lib/create.js b/lib/create.js
index fcf5814..78956a6 100644
--- a/lib/create.js
+++ b/lib/create.js
@@ -6,7 +6,7 @@ var stringify = require('./stringify');
 // creates an instance of a type, handling the optional new operator
 module.exports = function create(type, value, path) {
   if (isType(type)) {
-    return !type.meta.identity && typeof value === 'object' ? new type(value, path): type(value, path);
+    return !type.meta.identity && typeof value === 'object' && value !== null ? new type(value, path): type(value, path);
   }
 
   if (process.env.NODE_ENV !== 'production') {
diff --git a/package.json b/package.json
index 81a396a..0187446 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "tcomb",
-  "version": "3.2.5",
+  "version": "3.2.6",
   "description": "Type checking and DDD for JavaScript",
   "main": "index.js",
   "typings": "index.d.ts",


Test patch:
diff --git a/test/maybe.js b/test/maybe.js
index 2bc0e47..969e75b 100644
--- a/test/maybe.js
+++ b/test/maybe.js
@@ -91,6 +91,12 @@ describe('t.maybe(type, [name])', function () {
       assert.ok(typeof T(undefined) === 'undefined');
     });
 
+    it('should play well with JSON.stringify (#227)', function () {
+      var thing = t.struct({ foo: t.maybe(t.struct({ bar: t.String })) });
+      assert.strictEqual(JSON.stringify(thing({foo: null})), '{"foo":null}');
+      assert.strictEqual(JSON.stringify(thing({foo: undefined})), '{}');
+    });
+
   });
 
   describe('is(x)', function () {