serialization

Call default JsonSerializer in a JsonConverter for certain value type arrays

点点圈 提交于 2020-04-16 12:57:14
问题 I'm trying to achieve roughly what's described here: Recursively call JsonSerializer in a JsonConverter In short; To examine a value being deserialised, then either consume it in my own code, or hand it off the the default deserializer. The example uses a nifty trick to avoid the same custom code being called recursively: ... else if (reader.TokenType == JsonToken.StartObject) // Use DummyDictionary to fool JsonSerializer into not using this converter recursively dictionary = serializer

Django nested objects, different serializers GET and POST

家住魔仙堡 提交于 2020-04-16 02:27:32
问题 this is a follow-up to this question I had here. I can now POST a new AP object using user Primary Key and after commenting this line in the AP serializer user = UserIndexSerializer() : Postman request: { "user":1, "name":"Max AP 05" } However the problem that I now have is that the initial UserIdexSerializer is rendered useless. This serializer determines the fields to show in a GET request but in consequence imposes the fields required in a POST request. What I'm trying to do is: POST a new

ModelSerializer field validation for empty string

╄→尐↘猪︶ㄣ 提交于 2020-04-14 08:58:11
问题 I'm having a problem with django rest framework. My front is posting data to drf, and one of the fields could be null or an empty string "" . # models.py class Book(models.Model): title = models.CharField(max_length=100) publication_time = models.TimeField(null=True, blank=True) # serializers.py from rest_framework import serializers from .models import Book class BookSerializer(serializers.ModelSerializer): class Meta: model = Book fields = ('id', 'title', 'publication_time') publication

Json.NET deserializing contents of a JObject?

家住魔仙堡 提交于 2020-04-13 20:40:48
问题 If I have a JObject , which contains the property "Fields". How do I pull out the contents of this property to an object[] with deserialized elements? It seems like no matter what I do, I only get arrays of other JObjects. myJObject["Fields"] { "$type": "System.Object[], mscorlib", "$values": [ 123, "hello" ] } In this case, I want to get an object array containing a long 123 and the string "hello" . 回答1: Use ToObject(): var array = myJObject["Fields"].ToObject<object[]>(); Debug.Assert(array

django: form to json

。_饼干妹妹 提交于 2020-04-10 03:53:25
问题 I am trying to serialize my form into the json format. My view: form = CSVUploadForm(request.POST, request.FILES) data_to_json={} data_to_json = simplejson.dumps(form.__dict__) return HttpResponse(data_to_json, mimetype='application/json') I have the error <class 'django.forms.util.ErrorList'> is not JSON serializable . What to do to handle django forms? 回答1: You may want to look at the package called django-remote-forms: A package that allows you to serialize django forms, including fields

Change auto implemented properties to normal and deserialization with BinaryFormatter

♀尐吖头ヾ 提交于 2020-04-06 07:40:25
问题 I have an object with a property implemented like public String Bla {get;set;} After changing the implementation to something like private String _bla; public String Bla { get { return _bla; } set { _bla = value; } } on deserialzation, this Property comes up empty. i have lots of serialized data from the old implementation, and would like to load them with the new implementation is there any way, to change the implentation to be compatible with older binary files? EDIT: Some people might run

Change auto implemented properties to normal and deserialization with BinaryFormatter

♀尐吖头ヾ 提交于 2020-04-06 07:35:14
问题 I have an object with a property implemented like public String Bla {get;set;} After changing the implementation to something like private String _bla; public String Bla { get { return _bla; } set { _bla = value; } } on deserialzation, this Property comes up empty. i have lots of serialized data from the old implementation, and would like to load them with the new implementation is there any way, to change the implentation to be compatible with older binary files? EDIT: Some people might run

Flexible serialization with MultiParamTypeClasses

拜拜、爱过 提交于 2020-03-26 05:55:22
问题 I'm playing around with an idea for an extensible serialization library. I have the following typeclass: class Monoid m => BuilderS m a where cstr :: String -> a -> m The idea is that people can define instances for pairs of different serializers/types, like this: import qualified Data.Serialize.Builder as B instance Serialize a => BuilderS B.Builder a where cstr _ = B.fromByteString . encode And a usage example: sfPut :: (BuilderS a b, Monoid a) => WriterT a Identity () sfPut = do tell $

How to add an attribute which contains colon(:)for xml element and then serialize it in groovy?

99封情书 提交于 2020-03-25 19:14:10
问题 I have some test code snippet: ​import groovy.xml.XmlUtil class Greet { Greet() { } def salute() { println "Hello !" def input = """ <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application > <activity android:name="me.aolphn.MainActivity"> </activity> </application> </manifest> """ // def root = new XmlParser(false, true).parseText(input) def root = new XmlSlurper(false, true).parseText(input) root.'application'.@'android:txt'='this is txt' XmlUtil.serialize(root) }

How can I set the attributes and its values for a complex Json payload and serialize?

落花浮王杯 提交于 2020-03-25 16:05:39
问题 I have the following structure in my framework. I have a helper where I have the following Attribute code, Resolver code and the Serialization method. Link to this in the other part of the question How to create one model class to use with multiple API methods that require different JSON payloads? I now have any API that takes a Payload that is large with root object. How can I use the SerializeForApiMethod method for this, since it has the root object. I am trying to set the values in the