serialization

Unable to deserialize an object with a byte array property using Json.NET 8.0.1

馋奶兔 提交于 2019-12-23 10:29:50
问题 After upgrading a code base to use Json.NET 8.0.1, some deserialization stumbles. Using Json.NET 7.0.1 everything works fine. Apparently it is the deserialization of a property of type byte[] that causes the problem. If I remove the byte[] property it works fine. I can reproduce the behavior using this simple console application: internal class Program { private static void Main(string[] args) { Dictionary<string, Account> accounts; var jsonSerializerSettings = new JsonSerializerSettings {

xsd.exe generated classes don't serialize default value attributes

倖福魔咒の 提交于 2019-12-23 10:28:12
问题 I have few .cs files generated by xsd.exe by a XSD schema. My problem is that when i try to serialize those classes to xml, the attributes whose values match the default values defined in the xsd schema are not being serialized. I found out that my problem is solved when i remove [System.ComponentModel.DefaultValueAttribute(typeof(<someType>), "<SomeValue>")] attribute for the member representing a default field. So my question isn't there more elegant way to do this? For example is there any

Why is my class not serializable?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 10:23:40
问题 I have the following class: import java.awt.Color; import java.util.Vector; public class MyClass { private ImageSignature imageSignature; private class ImageSignature implements Serializable { private static final long serialVersionUID = -6552319171850636836L; private Vector<Color> colors = new Vector<Color>(); public void addColor(Color color) { colors.add(color); } public Vector<Color> getColors() { return colors; } } // Will be called after imageSignature was set, obviously public String

'Serialization of 'SimpleXMLElement' is not allowed Error insert in session xml value [duplicate]

旧城冷巷雨未停 提交于 2019-12-23 10:07:42
问题 This question already has answers here : Forcing a SimpleXML Object to a string, regardless of context (10 answers) Closed 6 years ago . Hi all I have a site developed in codeigniter. I'm parsing an xml that I retrieve from a server and I want to put the return value into a session variable. But return me this error: Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed My PHP version on my vps is: PHP Version 5.3.10-1ubuntu3.4 This is my

C# Partial deserialization

放肆的年华 提交于 2019-12-23 10:00:30
问题 So I have an xml that has a similar structure to this: <MyObject> <PropertyA>Value</PropertyA> <PropertyB>Value</PropertyB> <PropertyC>Value</PropertyC> <ArrayOfOtherObject> <OtherObject> <PropertyX>Value</PropertyX> <PropertyY>Value</PropertyY> <PropertyZ>Value</PropertyZ> </OtherObject> <OtherObject> <PropertyX>Value</PropertyX> <PropertyY>Value</PropertyY> <PropertyZ>Value</PropertyZ> </OtherObject> <OtherObject> <PropertyX>Value</PropertyX> <PropertyY>Value</PropertyY> <PropertyZ>Value<

Django-Rest-Framework: Paginate nested object

為{幸葍}努か 提交于 2019-12-23 09:59:46
问题 I have two models: class Book(models.Model): title = models.CharField(max_length=250) author = models.CharField(max_length=250) class WordInBook(models.Model): book = models.ForeignKey("Book") word = models.ForeignKey("Word") And corresponding serializers: class BookSerializer(ModelSerializer): wordinbook_set = WordInBookSerializer(many=True) class Meta: model = Book fields = ('id', 'title', 'author', 'wordinbook_set') class WordInBookSerializer(ModelSerializer): class Meta: model =

Understanding of FindBugs warning about serialVersionUID field

拟墨画扇 提交于 2019-12-23 09:53:19
问题 I have the following class signature and ClientEventSourc implements Serializable : public class Grid extends ClientEventSource implements Focusable, FramingBlockWrapper,LIMSEditableField Now FindBugs is listing this as dodgy : Class is Serializable, but doesn't define serialVersionUID This class implements the Serializable interface, but does not define a serialVersionUID field. A change as simple as adding a reference to a .class object will add synthetic fields to the class, which will

JSON.NET - How do I include Type Name Handling for primitive C# types that are stored in an array/list as Object type

ε祈祈猫儿з 提交于 2019-12-23 09:48:39
问题 I am using Newtonsoft JSON.NET to serialize/deserialize stuff for me. But I have this list wherein they are of Object type: var list = new List<Object>() { "hi there", 1, 2.33 }; When I serialize that with TypeNameHandling set to TypeNameHandling.All , I was expecting that it will also give a $type for each instance on the list but doesn't seem to be the case. Here is the actual output: { "$type": "System.Collections.Generic.List`1[[System.Object, mscorlib]], mscorlib", "$values": [ "hi there

What's the easiest method to change the namespace value using LINQ to XML?

天大地大妈咪最大 提交于 2019-12-23 09:48:04
问题 TL/DR: What's the easiest method to change the namespace value using LINQ to XML , say from xmlns:gcs="clr-namespace:NsOne;assembly=AsmOne" to xmlns:gcs="clr-namespace:NsTwo;assembly=AsmTwo" ? Why? because: I serialized Xaml using System.Windows.Markup.XamlWriter.Save(myControl) . I want to visualize this GUI appearance somewhere else (deserializing using System.Windows.Markup.XamlReader.Parse(raw) ), in another project. I don't want to link to the original assembly! I just need to change the

How to increase deserialization speed?

时间秒杀一切 提交于 2019-12-23 09:38:05
问题 Serializing/deserializing with BinaryFormatter, resulting serialized file is ~80MB in size. The deserialization takes a few minutes. How could I improve on this? Here's the deserialization code: public static Universe DeserializeFromFile(string filepath) { Universe universe = null; FileStream fs = new FileStream(filepath, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); try { universe = (Universe)bf.Deserialize(fs); } catch (SerializationException e) { Console.WriteLine("Failed to