/// <summary> /// /// </summary> /// <returns></returns> private object Parse() { _jsonReader.Read(); if (_jsonReader.TokenType != JsonToken.StartObject) { Debug.WriteLine("JSON Translation ERROR: not a valid JSON object. It should start with {"); } // move the first field in the document. typically it is the root element. _jsonReader.Read(); // find the classdescriptor for the root element. ClassDescriptor rootClassDescriptor = simplTypesScope.GetClassDescriptorByTag(_jsonReader.Value.ToString()); object root = rootClassDescriptor.GetInstance(); DeserializationPreHook(root, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPreHook(root, null); } // move to the first field of the object. _jsonReader.Read(); _jsonReader.Read(); // complete the object model from root and recursively of the fields it is composed of DeserializeObjectFields(root, rootClassDescriptor); translationContext.ResolveIdsForRefObjects(); return(root); }
/// <summary> /// /// </summary> /// <returns></returns> private object Parse() { NextEvent(); if (_xmlReader.NodeType != XmlNodeType.Element) { throw new SimplTranslationException("start of an element expected"); } String rootTag = CurrentTag; ClassDescriptor rootClassDescriptor = simplTypesScope .GetClassDescriptorByTag(rootTag); if (rootClassDescriptor == null) { throw new SimplTranslationException("cannot find the class descriptor for root element <" + rootTag + ">; make sure if simplTypesScope is correct."); } object root = rootClassDescriptor.GetInstance(); DeserializationPreHook(root, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPreHook(root, null); } DeserializeAttributes(root, rootClassDescriptor); CreateObjectModel(root, rootClassDescriptor, rootTag); return(root); }
/// <summary> /// /// </summary> /// <param name="currentFieldDescriptor"></param> /// <param name="currentTagName"></param> /// <param name="root"> </param> /// <returns></returns> private object GetSubRoot(FieldDescriptor currentFieldDescriptor, string currentTagName, object root) { Object subRoot; ClassDescriptor subRootClassDescriptor = currentFieldDescriptor.ChildClassDescriptor(currentTagName); String simplReference; if ((simplReference = GetSimplReference()) != null) { subRoot = translationContext.GetFromMap(simplReference); if (subRoot == null) { Debug.WriteLine("Cannot find simpl:ref " + simplReference); } return(subRoot); } if (subRootClassDescriptor == null) { Debug.WriteLine("ignoring element: " + currentTagName); //_xmlReader.Skip(); return(null); } subRoot = subRootClassDescriptor.GetInstance(); DeserializationPreHook(subRoot, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPreHook(subRoot, currentFieldDescriptor); } if (subRoot != null) { if (subRoot is ElementState && root is ElementState) { ((ElementState)subRoot).Parent = root as ElementState; } } DeserializeAttributes(subRoot, subRootClassDescriptor); if (!_xmlReader.IsEmptyElement) { CreateObjectModel(subRoot, subRootClassDescriptor, currentTagName); } else { DeserializationPostHook(subRoot, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPostHook(subRoot, null); } } return(subRoot); }
/// <summary> /// /// </summary> /// <returns></returns> private Object Parse() { NextHeader(); ClassDescriptor rootClassDescriptor = simplTypesScope.GetClassDescriptorByTlvId(_blockType); if (rootClassDescriptor == null) { throw new SimplTranslationException("cannot find the class descriptor for root element; make sure if translation scope is correct."); } object root = rootClassDescriptor.GetInstance(); DeserializationPreHook(root, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPreHook(root, null); } return(CreateObjectModel(root, rootClassDescriptor, _blockLength)); }
/// <summary> /// /// </summary> /// <param name="currentFieldDescriptor"></param> /// <param name="root"></param> /// <returns></returns> private Object GetSubRoot(FieldDescriptor currentFieldDescriptor, Object root) { ClassDescriptor subRootClassDescriptor = currentFieldDescriptor.GetChildClassDescriptor(_blockType); object subRoot = subRootClassDescriptor.GetInstance(); DeserializationPreHook(subRoot, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPreHook(subRoot, currentFieldDescriptor); } if (subRoot != null) { if (subRoot is ElementState && root is ElementState) { ((ElementState)subRoot).SetupInParent((ElementState)root); } } return(CreateObjectModel(subRoot, subRootClassDescriptor, _blockLength)); }
/// <summary> /// /// </summary> /// <param name="currentFieldDescriptor"></param> /// <param name="tagName"></param> /// <param name="simplId"></param> /// <returns></returns> private object GetSubRoot(FieldDescriptor currentFieldDescriptor, string tagName, out string simplId) { _jsonReader.Read(); Object subRoot = null; simplId = null; if (_jsonReader.Value != null && _jsonReader.Value.ToString().Equals(TranslationContext.JsonSimplRef)) { _jsonReader.Read(); simplId = _jsonReader.Value.ToString(); var referencedObject = translationContext.GetFromMap(simplId); if (referencedObject != null) { subRoot = referencedObject; } _jsonReader.Read(); } else { ClassDescriptor subRootClassDescriptor = currentFieldDescriptor.ChildClassDescriptor(tagName); if (subRootClassDescriptor != null) { subRoot = subRootClassDescriptor.GetInstance(); if (subRoot != null) { DeserializationPreHook(subRoot, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPreHook(subRoot, currentFieldDescriptor); } DeserializeObjectFields(subRoot, subRootClassDescriptor); } else { Debug.WriteLine("Skipping tag: " + tagName + ". Failed to create a new instance of " + currentFieldDescriptor.Name); var newObject = 1; while (_jsonReader.TokenType != JsonToken.EndObject || newObject > 0) { _jsonReader.Read(); if (_jsonReader.TokenType == JsonToken.StartObject) { newObject++; } else if (_jsonReader.TokenType == JsonToken.EndObject) { newObject--; } } } } else { Debug.WriteLine("skipping tag: " + tagName + ". not assignable to " + currentFieldDescriptor.Name); } } return(subRoot); }