Пример #1
0
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="VPackException"/>
        private void SerializeObject(
            string name,
            object entity,
            VPackBuilder builder,
            IDictionary <string, object> additionalFields)
        {
            IVPackSerializer serializer = this.serializers[entity.GetType()];

            if (serializer != null)
            {
                serializer.Serialize(builder, name, entity, this.serializationContext);
            }
            else
            {
                builder.Add(name, ValueType.OBJECT);
                this.SerializeFields(entity, builder, additionalFields);
                if (additionalFields.Count > 0)
                {
                    additionalFields.Clear();
                    builder.Close(true);
                }
                else
                {
                    builder.Close(false);
                }
            }
        }
Пример #2
0
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="VPackException"/>
        private void SerializeMap(
            string name,
            object value,
            VPackBuilder builder,
            Type keyType,
            IDictionary <string, object> additionalFields)
        {
            IDictionary map = (IDictionary)value;

            if (map.Count > 0)
            {
                IVPackKeyMapAdapter keyMapAdapter = this.GetKeyMapAdapter(keyType);
                if (keyMapAdapter != null)
                {
                    builder.Add(name, ValueType.OBJECT);
                    foreach (KeyValuePair <object, object> entry in map)
                    {
                        object entryValue = entry.Value;
                        this.AddValue(
                            keyMapAdapter.Serialize(entry.Key),
                            entryValue != null ? entryValue.GetType() : typeof(object),
                            entry.Value,
                            builder,
                            null,
                            additionalFields);
                    }

                    builder.Close();
                }
                else
                {
                    builder.Add(name, ValueType.ARRAY);
                    foreach (KeyValuePair <object, object> entry in map)
                    {
                        string s = null;
                        builder.Add(s, ValueType.OBJECT);
                        this.AddValue(ATTR_KEY, entry.Key.GetType(), entry.Key, builder, null, additionalFields);
                        this.AddValue(ATTR_VALUE, entry.Value.GetType(), entry.Value, builder, null, additionalFields);
                        builder.Close();
                    }

                    builder.Close();
                }
            }
            else
            {
                builder.Add(name, ValueType.OBJECT);
                builder.Close();
            }
        }
Пример #3
0
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="VPackException"/>
        private void SerializeIterable(
            string name,
            object value,
            VPackBuilder builder,
            IDictionary <string, object> additionalFields)
        {
            builder.Add(name, ValueType.ARRAY);
            for (IEnumerator iterator = ((IEnumerable)value).GetEnumerator(); iterator.MoveNext();)
            {
                object element = iterator.Current;
                this.AddValue(null, element.GetType(), element, builder, null, additionalFields);
            }

            builder.Close();
        }
Пример #4
0
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="VPackException"/>
        private void SerializeArray(
            string name,
            Array value,
            VPackBuilder builder,
            IDictionary <string, object> additionalFields)
        {
            builder.Add(name, ValueType.ARRAY);
            for (int i = 0; i < value.GetLength(0); i++)
            {
                object element = value.GetValue(i);
                this.AddValue(null, element.GetType(), element, builder, null, additionalFields);
            }

            builder.Close();
        }