private Deserializer GetAlreadyRegisteredDeserializer(DeserializerKey deserializerKey) { Deserializer alreadyRegisteredDeserializer; _deserializers.TryGetValue(deserializerKey, out alreadyRegisteredDeserializer); return(alreadyRegisteredDeserializer); }
public Deserializer ResolveDeserializer(DeserializerKey deserializerKey) { if (deserializerKey == null) { throw new ArgumentNullException("deserializerKey"); } Deserializer result; if (_deserializers.TryGetValue(deserializerKey, out result)) { return(result); } return(null); }
private object MatchObject() { var elements = new Dictionary <string, object>(); while (_reader.Read() && _reader.TokenType != JsonToken.EndObject) { if (_reader.TokenType == JsonToken.Comment) { continue; } if (_reader.TokenType != JsonToken.PropertyName) { throw Exceptions.UnexpectedTokenEncountered(_reader.TokenType); } var key = (string)_reader.Value; object value = MatchValue(); elements.Add(key, value); } var objectProperties = new ObjectProperties(elements); //check if wrapped built-in type if (objectProperties.IsBuiltInTypeInPackformat) { return(objectProperties.GetBuiltInTypeUnpacked()); } //build up object if (objectProperties.IsInPackformat) { var deserializerKey = new DeserializerKey(objectProperties.TypeName, objectProperties.Version); var typeUnpacker = _deserializers.ResolveDeserializer(deserializerKey); //if we don't have a real builder we'll throw an exception when someone tries to get the data var builderFunc = (typeUnpacker == null ? null : typeUnpacker.GetDeserializerFunc(_serializerInstanceStore)) ?? (i => { throw Exceptions.CannotFindDeserializer(i); }); return(new ObjectInPackedForm(objectProperties, builderFunc)); } //TODO handle the case when no name and/or version is present - some JSON not serialized with shapeshifter throw Exceptions.InvalidInput(); }
public bool Equals(DeserializerKey other) { return string.Equals(_packedName, other._packedName) && _version == other._version; }
protected Deserializer(string packformatName, uint version) { _key = new DeserializerKey(packformatName, version); }