diff --git a/CHANGELOG.md b/CHANGELOG.md index 5990ec7..8a4f50b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ - `JsonDecoder`: - `decode`: optimize resolution for `T`/`type` `dynamic`/`Object` (any type). +- `JsonConverter` (`JsonEncoder` & `JsonDecoder`): + - Added `isStandard`. + ## 2.4.1 - `JsonEntityCache`: diff --git a/lib/src/reflection_factory_json.dart b/lib/src/reflection_factory_json.dart index ee5f342..35d7353 100644 --- a/lib/src/reflection_factory_json.dart +++ b/lib/src/reflection_factory_json.dart @@ -364,6 +364,9 @@ class JsonCodec { /// JSON decoder integrated with [ReflectionFactory]. abstract class JsonConverter implements dart_convert.Converter { + /// Returns `true` if this instance's configuration is equivalent to the default configuration. + bool get isStandard; + static bool isPrimitiveType(Type type) { return type == String || type == int || @@ -588,6 +591,19 @@ class _JsonEncoder extends dart_convert.Converter this.autoResetEntityCache, ) : entityCache = entityCache ?? JsonEntityCacheSimple(); + @override + bool get isStandard => + identical(this, _JsonEncoder._defaultEncoder) || + (maskField == null && + removeField == null && + !removeNullFields && + toEncodableProvider == null && + toEncodable == null && + !forceDuplicatedEntitiesAsID && + autoResetEntityCache && + maskText == '***' && + entityCache is JsonEntityCacheSimple); + @override void resetEntityCache() { entityCache.clearCachedEntities(); @@ -915,7 +931,8 @@ abstract class JsonDecoder extends JsonConverter { JsonEntityCache? entityCache, bool forceDuplicatedEntitiesAsID = false, bool autoResetEntityCache = true}) { - if (jsomMapDecoderProvider == null && + if (jsonValueDecoderProvider == null && + jsomMapDecoderProvider == null && jsomMapDecoder == null && jsomMapDecoderAsyncProvider == null && jsomMapDecoderAsync == null && @@ -1095,6 +1112,20 @@ class _JsonDecoder extends dart_convert.Converter this.autoResetEntityCache, ) : entityCache = entityCache ?? JsonEntityCacheSimple(); + @override + bool get isStandard => + identical(this, _JsonDecoder._defaultDecoder) || + (jsonValueDecoderProvider == null && + jsomMapDecoderProvider == null && + jsomMapDecoder == null && + jsomMapDecoderAsyncProvider == null && + jsomMapDecoderAsync == null && + iterableCaster == null && + mapCaster == null && + !forceDuplicatedEntitiesAsID && + autoResetEntityCache && + entityCache is JsonEntityCacheSimple); + @override void resetEntityCache() { entityCache.clearCachedEntities(); @@ -1962,7 +1993,7 @@ class _JsonDecoder extends dart_convert.Converter var json = dart_convert.json.decode(encodedJson); - if (typeInfo.isAnyType) { + if (typeInfo.isAnyType && isStandard) { return json as T; } @@ -2007,7 +2038,7 @@ class _JsonDecoder extends dart_convert.Converter var json = dart_convert.json.decode(encodedJson); - if (typeInfo.isAnyType) { + if (typeInfo.isAnyType && isStandard) { return json as T; }