serializer

C# DataContractJsonSerializer fails when value can be an array or a single item

人盡茶涼 提交于 2020-01-01 05:39:30
问题 I use the DataContractJsonSerializer to parse a json string into a object hierarchie. The json string looks like this: { "groups": [ { "attributes": [ { "sortOrder": "1", "value": "A" }, { "sortOrder": "2", "value": "B" } ] }, { "attributes": { "sortOrder": "1", "value": "C" } } ] } As you can see the sub value of "attributes" can be an array or a single item. I found the code part where the problem occures: [DataContract] public class ItemGroup { [DataMember(Name="attributes")] public List

Django - How can you include annotated results in a serialized QuerySet?

与世无争的帅哥 提交于 2019-12-29 09:09:15
问题 How can you include annotated results in a serialized QuerySet? data = serializer.serialize(Books.objects.filter(publisher__id=id).annotate(num_books=Count('related_books')), use_natural_keys=True) However the key/value pare {'num_books': number} is not include into the json result. I've been searching for similar questions on the internet, but i didn't found a solution that worked for me. Here is a similar case: http://python.6.x6.nabble.com/How-can-you-include-annotated-results-in-a

Android creating and writing xml to file

雨燕双飞 提交于 2019-12-29 05:33:06
问题 I'm taking a course on android app development and trying to create and write an xml file to the internal storage on the android. I am having issues with how to set this up initially, as far as the methods. I've written most of it but have errors that I can't figure out. Maybe because I've been working on this all day, I don't know. Here's my code for this class. Errors I'm getting are illegal modifiers on public String treasures and FileOutputStream. Any help would be appreciated. Ok, I

rails active model serializer not doing anything

柔情痞子 提交于 2019-12-25 14:05:51
问题 I am using the the GEM found here: https://rubygems.org/gems/active_model_serializers I've created the serializer using rails g, added it to the controller where I return json but it is still returning everything and not the defined attributes - Any ideas? module Api module V1 class ProductDetailsController < ApplicationController def show @prod = ProductPrice.joins(:product, :retailer).select("*") render json: @prod, serializer: ProductDetailSerializer end end end end class

WCF custom serializer do not work

血红的双手。 提交于 2019-12-25 01:24:59
问题 Want to replace wcf serializer with a custom one. After googling I've found examples. But it do not work. Here is my code: Substitutor: internal class MySerializerSubstitutor : DataContractSerializerOperationBehavior { private static readonly MySerializer _serializer = new MySerializer(); public MySerializerSubstitutor (OperationDescription operationDescription) : base(operationDescription) { } public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type>

WCF - How to serialize and deserialize in JSON?

你说的曾经没有我的故事 提交于 2019-12-23 12:19:08
问题 I have written few classes (Data contracts and Service contracts) in WCF and i'm trying to serialize and deserialize in JSON. If i need the following JSON structure, how would i create the DataContract(s): { "response": { "locations": { "location": [ { "id": "12", "name": "Hello", "statusid": "78" }, { "id": "5", "name": "Ann", "statusid": "8" } ] }, "error": "404 error" } } The structure above is pretty straight forward and under locations there can be several location details as mentioned

Need Jackson serializer for Double and need to specify precision at runtime

流过昼夜 提交于 2019-12-22 05:06:55
问题 There are many posts about creating Jackson serializers for numbers, currency, etc. For engineering applications, there is often a need to set the precision on numbers based on the units or other criteria. For example, spatial coordinates might be constrained to 5 or 6 digits after the decimal point, and temperature might be constrained to 2 digits after the decimal point. Default serializer behavior that has too many digits or truncated exponential notation is not good. What I need is

Is it possible to write Flume headers to HDFS sink and drop the body?

試著忘記壹切 提交于 2019-12-20 03:41:10
问题 The text_with_headers serializer (HDFS sink serializer) allows to save the Flume event headers rather than discarding them. The output format consists of the headers, followed by a space, then the body payload. We would like to drop the body and retain the headers only. For the HBase sink, the "RegexHbaseEventSerializer" allows us to transform the events. But I am unable to find such a provision for the HDFS sink. 回答1: You can set serializer property to header_and_text , which outputs both

Pass request context to serializer from Viewset in Django Rest Framework

我的未来我决定 提交于 2019-12-18 11:38:33
问题 I have a case where the values for a serializer field depend on the identity of the currently logged in user. I have seen how to add the user to the context when initializing a serializer, but I am not sure how to do this when using a ViewSet, as you only supply the serializer class and not the actual serializer instance. Basically I would like to know how to go from: class myModelViewSet(ModelViewSet): queryset = myModel.objects.all() permission_classes = [DjangoModelPermissions] serializer

Using reflection to serialize files

流过昼夜 提交于 2019-12-12 22:30:37
问题 In my company's application, there's a viewer that will take a message and create an XML document out of it so it can be presented nicely for the customers. Each message has their own class and so far must individually be written like in the examle below. The class name is given in the "m_msgTypeVersion", so I figured it should be possible to use reflection to generalize the cases in this switch statement so it doesn't have to be updated when new message types are added to the application.