Skip to content

Commit bda0253

Browse files
committed
Made configuration more like Jackson.
Added ability to change config on the mapper post instantiation Added ability to always ignore unknowns. Added option to throw an exception on unknowns. Made BadConfig exception extend the base mapper exception.
1 parent db23ea4 commit bda0253

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/Weasel/JsonMarshaller/Config/Deserialization/Feature.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,26 @@
66
*/
77
namespace Weasel\JsonMarshaller\Config\Deserialization;
88

9-
9+
/**
10+
* Features for config general mapper behaviour.
11+
* These are the keys to be passed to the mapper configure() method.
12+
*/
1013
interface Feature {
14+
/**
15+
* bool. When true, throw an exception (UnknownPropertyException) on encountering an unknown property in the JSON and
16+
* there's no AnySetter configured (or ignoreUnknown isn't set.) Default: false.
17+
*/
1118
const FAIL_ON_UNKNOWN_PROPERTIES = "deserialization::fail_on_unknown";
19+
/**
20+
* bool. When true trigger an E_USER_WARNING on encountering an unknown property in the JSON and there's no AnySetter
21+
* configured (or ignoreUnknown isn't set.) Default: true.
22+
*/
1223
const WARN_ON_UNKNOWN_PROPERTIES = "deserialization::warn_on_unknown";
1324

25+
/**
26+
* bool. When true apply strict type checking. JSON types encountered are expected to match the PHP types we're
27+
* going to deserialize to. If they don't, throw an exception. Default true.
28+
*/
1429
const STRICT_TYPES = "deserialization::strict_types";
1530

16-
1731
}

lib/Weasel/JsonMarshaller/JsonMapper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function __construct(JsonConfigProvider $configProvider, $strict = true)
5656
}
5757
}
5858

59+
/**
60+
* @param string $key One of the Config\*\Feature:: constants.
61+
* @param mixed $value Appropriate value for the config option. See their documentation.
62+
*/
5963
public function configure($key, $value)
6064
{
6165
$this->mapperConfig[$key] = $value;

0 commit comments

Comments
 (0)