ReadJsonValue() static private method

static private ReadJsonValue ( DataContract contract, XmlReaderDelegator reader, System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson context ) : object
contract DataContract
reader XmlReaderDelegator
context System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson
return object
Beispiel #1
0
        internal override object?InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName)
        {
            if (MaxItemsInObjectGraph == 0)
            {
                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph));
            }

            if (verifyObjectName)
            {
                if (!InternalIsStartObject(xmlReader))
                {
                    throw XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElement, XmlDictionaryString.Empty, RootName), xmlReader);
                }
            }
            else if (!IsStartElement(xmlReader))
            {
                throw XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElementAtDeserialize, XmlNodeType.Element), xmlReader);
            }

            DataContract contract = RootContract;

            if (contract.IsPrimitive && object.ReferenceEquals(contract.UnderlyingType, _rootType))// handle Nullable<T> differently
            {
                return(DataContractJsonSerializer.ReadJsonValue(contract, xmlReader, null));
            }

            XmlObjectSerializerReadContextComplexJson context = XmlObjectSerializerReadContextComplexJson.CreateContext(this, contract);

            return(context.InternalDeserialize(xmlReader, _rootType, contract, null, null));
        }
        protected override object ReflectionReadDictionaryItem(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, CollectionDataContract collectionContract)
        {
            var jsonContext = context as XmlObjectSerializerReadContextComplexJson;

            Debug.Assert(jsonContext != null);
            Debug.Assert(collectionContract.Kind == CollectionKind.Dictionary || collectionContract.Kind == CollectionKind.GenericDictionary);
            context.ReadAttributes(xmlReader);

            var itemContract = XmlObjectSerializerWriteContextComplexJson.GetRevisedItemContract(collectionContract.ItemContract);

            return(DataContractJsonSerializer.ReadJsonValue(itemContract, xmlReader, jsonContext));
        }
 object ReadCollectionItem(CollectionDataContract collectionContract, Type itemType)
 {
     if (collectionContract.Kind == CollectionKind.Dictionary || collectionContract.Kind == CollectionKind.GenericDictionary)
     {
         context.ResetAttributes();
         var revisedContract = XmlObjectSerializerWriteContextComplexJson.GetRevisedItemContract(collectionContract.ItemContract);
         var v = DataContractJsonSerializer.ReadJsonValue(revisedContract, xmlReader, context);
         return(CodeInterpreter.ConvertValue(v, Globals.TypeOfObject, itemType));
     }
     else
     {
         return(ReadValue(itemType, JsonGlobals.itemString));
     }
 }
Beispiel #4
0
        public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
        {
            object obj;
            string contentMode = jsonReader.GetAttribute(JsonGlobals.typeString);

            switch (contentMode)
            {
            case JsonGlobals.nullString:
                jsonReader.Skip();
                obj = null;
                break;

            case JsonGlobals.booleanString:
                obj = jsonReader.ReadElementContentAsBoolean();
                break;

            case JsonGlobals.stringString:
            case null:
                obj = jsonReader.ReadElementContentAsString();
                break;

            case JsonGlobals.numberString:
                obj = ParseJsonNumber(jsonReader.ReadElementContentAsString());
                break;

            case JsonGlobals.objectString:
                jsonReader.Skip();
                obj = new object();
                break;

            case JsonGlobals.arrayString:
                // Read as object array
                return(DataContractJsonSerializer.ReadJsonValue(DataContract.GetDataContract(Globals.TypeOfObjectArray), jsonReader, context));

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.JsonUnexpectedAttributeValue, contentMode)));
            }

            if (context != null)
            {
                context.AddNewObject(obj);
            }
            return(obj);
        }
Beispiel #5
0
 protected override object?ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
 {
     return(DataContractJsonSerializer.ReadJsonValue(dataContract, reader, this));
 }