diff --git a/src/LaunchDarkly/LDUser.php b/src/LaunchDarkly/LDUser.php index fe8c14fa1..fb6ea96cb 100644 --- a/src/LaunchDarkly/LDUser.php +++ b/src/LaunchDarkly/LDUser.php @@ -117,7 +117,7 @@ public function toJSON() { if (isset($this->_lastName)) { $json['lastName'] = $this->_lastName; } - if (isset($this->_custom)) { + if (isset($this->_custom) && !empty($this->_custom)) { $json['custom'] = $this->_custom; } if (isset($this->_anonymous)) { diff --git a/tests/LDUserTest.php b/tests/LDUserTest.php index ca684f241..106b2a441 100644 --- a/tests/LDUserTest.php +++ b/tests/LDUserTest.php @@ -21,6 +21,13 @@ public function testCoerceLDUserKey() { $this->assertEquals("string", gettype($json['key'])); } + public function testEmptyCustom() { + $builder = new LDUserBuilder("foo@bar.com"); + $user = $builder->build(); + $json = $user->toJSON(); + $this->assertTrue(!isset($json['custom'])); + } + public function testLDUserSecondary() { $builder = new LDUserBuilder("foo@bar.com"); $user = $builder->secondary("secondary")->build();