/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="rootClassDescriptor"></param> /// <returns></returns> private void DeserializeAttributes(object root, ClassDescriptor rootClassDescriptor) { while (_xmlReader.MoveToNextAttribute()) { String tag = _xmlReader.Name; String value = _xmlReader.Value; //silently ignore simpl namespace. if (tag.Equals(TranslationContext.SimplNamespace)) { continue; } if (tag.Equals(TranslationContext.SimplId)) { translationContext.MarkAsUnmarshalled(value, root); } else { FieldDescriptor attributeFieldDescriptor = rootClassDescriptor.GetFieldDescriptorByTag(tag); if (attributeFieldDescriptor != null) { attributeFieldDescriptor.SetFieldToScalar(root, value, translationContext); } else { Debug.WriteLine("ignoring attribute: " + tag); } } } _xmlReader.MoveToElement(); }
/// <summary> /// /// </summary> /// <param name="theObject"></param> /// <param name="objectClassDescriptor"></param> private void DeserializeObjectFields(object theObject, ClassDescriptor objectClassDescriptor) { FieldDescriptor currentFieldDescriptor = null; bool insideWrapped = false; while (_jsonReader.TokenType != JsonToken.EndObject) { var currentJsonProperty = _jsonReader.Value; if (currentJsonProperty == null || _jsonReader.TokenType != JsonToken.PropertyName) { Debug.WriteLine("should have found PropertyName, but instead found " + _jsonReader.TokenType); _jsonReader.Skip(); } var currentTag = _jsonReader.Value.ToString(); if (!HandleSimplId(currentTag, theObject)) { currentFieldDescriptor = currentFieldDescriptor != null && currentFieldDescriptor.FdType == FieldTypes.Wrapper ? currentFieldDescriptor.WrappedFd : objectClassDescriptor.GetFieldDescriptorByTag(currentTag); if (currentFieldDescriptor == null) { currentFieldDescriptor = FieldDescriptor.MakeIgnoredFieldDescriptor(currentTag); Debug.WriteLine("ignoring " + currentTag); _jsonReader.Skip(); } switch (currentFieldDescriptor.FdType) { case FieldTypes.Scalar: DeserializeScalar(theObject, currentFieldDescriptor); break; case FieldTypes.CompositeElement: DeserializeComposite(theObject, currentFieldDescriptor); if (insideWrapped) { insideWrapped = false; _jsonReader.Read(); } break; case FieldTypes.CollectionScalar: DeserializeScalarCollection(theObject, currentFieldDescriptor); break; case FieldTypes.CollectionElement: DeserializeCompositeCollection(theObject, currentFieldDescriptor); break; case FieldTypes.MapElement: DeserializeCompositeMap(theObject, currentFieldDescriptor); break; case FieldTypes.Wrapper: // don't do this for collections or maps because they are always wrapped (even when nowrap is specified) // and this is handled in respective method calls. if (currentFieldDescriptor.WrappedFd.IsComposite) { _jsonReader.Read(); _jsonReader.Read(); if (_jsonReader.TokenType != JsonToken.PropertyName) { // expecting property name, but found something else. not a properly wrapped composite. while (_jsonReader.TokenType != JsonToken.EndObject) { _jsonReader.Skip(); } _jsonReader.Read(); continue; } insideWrapped = true; } // currentFieldDescriptor = currentFieldDescriptor.WrappedFd; // if (currentFieldDescriptor.FdType == FieldTypes.CompositeElement) // goto case FieldTypes.CompositeElement; // if (currentFieldDescriptor.FdType == FieldTypes.CollectionScalar) // goto case FieldTypes.CollectionScalar; // if (currentFieldDescriptor.FdType == FieldTypes.CollectionElement) // goto case FieldTypes.CollectionElement; // if (currentFieldDescriptor.FdType == FieldTypes.MapElement) // goto case FieldTypes.MapElement; break; } } // if simpl.id or non-wrapper field descriptor, advance to next token. if (currentFieldDescriptor == null || currentFieldDescriptor.FdType != FieldTypes.Wrapper) { _jsonReader.Read(); } } DeserializationPostHook(theObject, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPostHook(theObject, null); } }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="rootClassDescriptor"></param> /// <param name="rootTag"></param> private void CreateObjectModel(object root, ClassDescriptor rootClassDescriptor, string rootTag) { FieldDescriptor currentFieldDescriptor = new FieldDescriptor(); while (NextEvent() && (_xmlReader.NodeType != XmlNodeType.EndElement || !CurrentTag.Equals(rootTag))) { if (_xmlReader.NodeType != XmlNodeType.Element) { continue; } if (currentFieldDescriptor.FdType != FieldTypes.Wrapper) { currentFieldDescriptor = rootClassDescriptor.GetFieldDescriptorByTag(CurrentTag); } if (currentFieldDescriptor == null) { //Debug.WriteLine("ignoring tag " + CurrentTag); currentFieldDescriptor = FieldDescriptor.MakeIgnoredFieldDescriptor(CurrentTag); if (!_xmlReader.IsEmptyElement) { SkipTag(CurrentTag); } continue; } switch (currentFieldDescriptor.FdType) { case FieldTypes.Scalar: DeserializeScalar(root, currentFieldDescriptor); break; case FieldTypes.CompositeElement: DeserializeComposite(root, currentFieldDescriptor); break; case FieldTypes.CollectionScalar: DeserializeScalarCollectionElement(root, currentFieldDescriptor); break; case FieldTypes.CollectionElement: DeserializeCompositeCollectionElement(root, currentFieldDescriptor); break; case FieldTypes.MapElement: DeserializeCompositeMapElement(root, currentFieldDescriptor); break; case FieldTypes.Wrapper: currentFieldDescriptor = currentFieldDescriptor.WrappedFd; switch (currentFieldDescriptor.FdType) { case FieldTypes.CollectionScalar: DeserializeScalarCollection(root, currentFieldDescriptor); break; case FieldTypes.CollectionElement: DeserializeCompositeCollection(root, currentFieldDescriptor); break; case FieldTypes.MapElement: DeserializeCompositeMap(root, currentFieldDescriptor); break; case FieldTypes.CompositeElement: DeserializeWrappedComposite(root, currentFieldDescriptor); break; } break; case FieldTypes.IgnoredElement: SkipTag(CurrentTag); break; default: NextEvent(); break; } } DeserializationPostHook(root, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPostHook(root, null); } }
/// <summary> /// /// </summary> /// <param name="theObject"></param> /// <param name="objectClassDescriptor"></param> private void DeserializeObjectFields(object theObject, ClassDescriptor objectClassDescriptor) { FieldDescriptor currentFieldDescriptor = null; bool insideWrapped = false; while (_jsonReader.TokenType != JsonToken.EndObject) { var currentJsonProperty = _jsonReader.Value; if (currentJsonProperty == null || _jsonReader.TokenType != JsonToken.PropertyName) { Debug.WriteLine("should have found PropertyName, but instead found " +_jsonReader.TokenType); _jsonReader.Skip(); } var currentTag = _jsonReader.Value.ToString(); if (!HandleSimplId(currentTag, theObject)) { currentFieldDescriptor = currentFieldDescriptor != null && currentFieldDescriptor.FdType== FieldTypes.Wrapper ? currentFieldDescriptor.WrappedFd : objectClassDescriptor.GetFieldDescriptorByTag(currentTag); if (currentFieldDescriptor == null) { currentFieldDescriptor = FieldDescriptor.MakeIgnoredFieldDescriptor(currentTag); Debug.WriteLine("ignoring " + currentTag); _jsonReader.Skip(); } switch (currentFieldDescriptor.FdType) { case FieldTypes.Scalar: DeserializeScalar(theObject, currentFieldDescriptor); break; case FieldTypes.CompositeElement: DeserializeComposite(theObject, currentFieldDescriptor); if (insideWrapped) { insideWrapped = false; _jsonReader.Read(); } break; case FieldTypes.CollectionScalar: DeserializeScalarCollection(theObject, currentFieldDescriptor); break; case FieldTypes.CollectionElement: DeserializeCompositeCollection(theObject, currentFieldDescriptor); break; case FieldTypes.MapElement: DeserializeCompositeMap(theObject, currentFieldDescriptor); break; case FieldTypes.Wrapper: // don't do this for collections or maps because they are always wrapped (even when nowrap is specified) // and this is handled in respective method calls. if (currentFieldDescriptor.WrappedFd.IsComposite) { _jsonReader.Read(); _jsonReader.Read(); if (_jsonReader.TokenType != JsonToken.PropertyName) { // expecting property name, but found something else. not a properly wrapped composite. while(_jsonReader.TokenType != JsonToken.EndObject) _jsonReader.Skip(); _jsonReader.Read(); continue; } insideWrapped = true; } // currentFieldDescriptor = currentFieldDescriptor.WrappedFd; // if (currentFieldDescriptor.FdType == FieldTypes.CompositeElement) // goto case FieldTypes.CompositeElement; // if (currentFieldDescriptor.FdType == FieldTypes.CollectionScalar) // goto case FieldTypes.CollectionScalar; // if (currentFieldDescriptor.FdType == FieldTypes.CollectionElement) // goto case FieldTypes.CollectionElement; // if (currentFieldDescriptor.FdType == FieldTypes.MapElement) // goto case FieldTypes.MapElement; break; } } // if simpl.id or non-wrapper field descriptor, advance to next token. if (currentFieldDescriptor == null || currentFieldDescriptor.FdType != FieldTypes.Wrapper) _jsonReader.Read(); } DeserializationPostHook(theObject, translationContext); if (deserializationHookStrategy != null) deserializationHookStrategy.DeserializationPostHook(theObject, null); }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="rootClassDescriptor"></param> /// <returns></returns> private void DeserializeAttributes(object root, ClassDescriptor rootClassDescriptor) { while (_xmlReader.MoveToNextAttribute()) { String tag = _xmlReader.Name; String value = _xmlReader.Value; //silently ignore simpl namespace. if (tag.Equals(TranslationContext.SimplNamespace)) continue; if(tag.Equals(TranslationContext.SimplId)) { translationContext.MarkAsUnmarshalled(value, root); } else { FieldDescriptor attributeFieldDescriptor = rootClassDescriptor.GetFieldDescriptorByTag(tag); if (attributeFieldDescriptor != null) { attributeFieldDescriptor.SetFieldToScalar(root, value, translationContext); } else { Debug.WriteLine("ignoring attribute: " + tag); } } } _xmlReader.MoveToElement(); }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="rootClassDescriptor"></param> /// <param name="rootTag"></param> private void CreateObjectModel(object root, ClassDescriptor rootClassDescriptor, string rootTag) { FieldDescriptor currentFieldDescriptor = new FieldDescriptor(); while (NextEvent() && (_xmlReader.NodeType != XmlNodeType.EndElement || !CurrentTag.Equals(rootTag))) { if (_xmlReader.NodeType != XmlNodeType.Element) continue; if(currentFieldDescriptor.FdType != FieldTypes.Wrapper) currentFieldDescriptor = rootClassDescriptor.GetFieldDescriptorByTag(CurrentTag); if (currentFieldDescriptor == null) { //Debug.WriteLine("ignoring tag " + CurrentTag); currentFieldDescriptor = FieldDescriptor.MakeIgnoredFieldDescriptor(CurrentTag); if (!_xmlReader.IsEmptyElement) SkipTag(CurrentTag); continue; } switch (currentFieldDescriptor.FdType) { case FieldTypes.Scalar: DeserializeScalar(root, currentFieldDescriptor); break; case FieldTypes.CompositeElement: DeserializeComposite(root, currentFieldDescriptor); break; case FieldTypes.CollectionScalar: DeserializeScalarCollectionElement(root, currentFieldDescriptor); break; case FieldTypes.CollectionElement: DeserializeCompositeCollectionElement(root, currentFieldDescriptor); break; case FieldTypes.MapElement: DeserializeCompositeMapElement(root, currentFieldDescriptor); break; case FieldTypes.Wrapper: currentFieldDescriptor = currentFieldDescriptor.WrappedFd; switch (currentFieldDescriptor.FdType) { case FieldTypes.CollectionScalar: DeserializeScalarCollection(root, currentFieldDescriptor); break; case FieldTypes.CollectionElement: DeserializeCompositeCollection(root, currentFieldDescriptor); break; case FieldTypes.MapElement: DeserializeCompositeMap(root, currentFieldDescriptor); break; case FieldTypes.CompositeElement: DeserializeWrappedComposite(root, currentFieldDescriptor); break; } break; case FieldTypes.IgnoredElement: SkipTag(CurrentTag); break; default: NextEvent(); break; } } DeserializationPostHook(root, translationContext); if (deserializationHookStrategy != null) deserializationHookStrategy.DeserializationPostHook(root, null); }