How do you use XMLSerialize for Enum typed properties in c#?

As per Darin Dimitrov’s answer – only extra thing I’d point out is that if you want control over how your enum fields are serialized out then you can decorate each field with the XmlEnum attribute. public enum Simple { [XmlEnum(Name=”First”)] one, [XmlEnum(Name=”Second”)] two, [XmlEnum(Name=”Third”)] three, }

Disabled fields not picked up by serializeArray

Try this var data = $(‘form’).serializeAllArray(); And here is the small plugin that is used (function ($) { $.fn.serializeAllArray = function () { var obj = {}; $(‘input’,this).each(function () { obj[this.name] = $(this).val(); }); return $.param(obj); } })(jQuery); You can also try enabling all your element’s just to serialize them and then disable them after … Read more

How to serialize byte[] as simple JSON Array and not as base64 in JSON.net?

JSON.NET is selecting the BinaryConverter to read and write an array of bytes. You can see in the source that it uses the WriteValue operation on the JsonWriter class with the array of bytes which causes them to be written to as Base-64. To modify this, you can write your own converter which reads and … Read more

Django REST Framework: raise error when extra fields are present on POST

Came across this question and found that using object level validation is a bit easier. This entails simply defining a validate method: class ModelASerializer(serializers.ModelSerializer): … def validate(self, data): if hasattr(self, ‘initial_data’): unknown_keys = set(self.initial_data.keys()) – set(self.fields.keys()) if unknown_keys: raise ValidationError(“Got unknown fields: {}”.format(unknown_keys)) return data

Django REST Serializer Method Writable Field

Here is a read/write serializer method field: class ReadWriteSerializerMethodField(serializers.SerializerMethodField): def __init__(self, method_name=None, **kwargs): self.method_name = method_name kwargs[‘source’] = ‘*’ super(serializers.SerializerMethodField, self).__init__(**kwargs) def to_internal_value(self, data): return {self.field_name: data}

What’s the difference between .serialize() and .serializeArray()?

serializeArray creates an array (not a “json array” — there is no such thing); you can test this yourself with console.log($(“#myform”).serializeArray()). On the other hand, serialize creates a query string that’s meant to be part of an HTTP request. Both representations are equivalent in the sense that using appropriate code you can convert one to … Read more