serialization

active model serializer with virtual attribute - Rails 4

纵然是瞬间 提交于 2019-12-24 12:42:07
问题 I am currently making API with RoR, and I need to create an object with virtual attributes and associated object. The problem is that serializer does not kick in when I return an object with virtual attribute. Here is the returned object from foo_controller { :id=>280, :virtual=>"y8st07ef7u" :user_id=>280 } :virtual is a virtual attribute and user_id is an id of associated table - User. My goal is to make this { :id=>280, :virtual=>"y8st07ef7u", :user=>{ :id=>280, :name=>'foo' } } Foo

How do I change my previously saved List type to serialize into an Array type

只愿长相守 提交于 2019-12-24 12:41:47
问题 Previously, we serialized a property as a List<byte> Now we want to change it to be a byte[] . It was out understanding that you should be able to swap out collection types freely between version but we get a ProtoBuf.ProtoException [TestFixture, Category("Framework")] class CollectionTypeChange { [Test] public void TestRoundTrip() { var bytes = new List<byte>() {1,2,4}; var a = new ArrayHolder(bytes); var aCopy = Deserialize<ArrayHolder>(Serialize(a)); //Passes Assert.That(aCopy

Serializing GradientBrush

你说的曾经没有我的故事 提交于 2019-12-24 12:35:20
问题 I'm trying to save a Brush object using serializing but I get error below: Type 'System.Windows.Media.LinearGradientBrush' in Assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable How can I save a Brush object into a file? 回答1: Try this... var brush = new LinearGradientBrush(new GradientStopCollection( new GradientStop[] { new GradientStop(Colors.Blue, 2.0), new GradientStop(Colors.Red, 3.0) })); using (var outfile = File

Jackson - cannot serialize generics

十年热恋 提交于 2019-12-24 12:29:16
问题 Here is my class hierarchy: Banana class: @JsonTypeName("banana") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type") public class Banana<T, M> extends Fruit<T, M> { Fruit class: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME) @JsonSubTypes({ @JsonSubTypes.Type(value = Banana.class, name = "banana")}) public class Fruit<T, M> { private boolean ok; private T main; Car class: @JsonTypeName("car") public class Car extends Vehicle { Abstract Vehicle class:

Getting Dill Memory Error when loading serialized object, how to fix?

纵然是瞬间 提交于 2019-12-24 12:27:26
问题 I am getting a dill/pickle memory error when loading a serialized object file. I am not quite sure what is happening and I am unsure on how to fix it. When I call: stat_bundle = train_batch_iterator(clf, TOTAL_TRAINED_EVENTS) The code traces to the train_batch_iterator function in which it loads a serialized object and trains the classifier with the data within the object. This is the code: def train_batch_iterator(clf, tte): plot_data = [] # initialize plot data array for file in glob.glob('

XmlArray Serialization - How can I make the serializer ignore the class name of items in a list?

一曲冷凌霜 提交于 2019-12-24 12:22:48
问题 I have a class that, among other properties, has a list of MyObject. public class MyClass { ... [XmlArray("OBJECT")] public List<MyObject> Objects { get; set; } ... } Each MyObject has two properties, PropA and PropB. public class MyObject { public string PropA {get;set;} public string PropB {get;set;} } The XML Serializer returns this XML: <OBJECT> <MyObject> <PropA>A1</PropA> <PropB>B1</PropB> </MyObject> <MyObject> <PropA>A2</PropA> <PropB>B2</PropB> </MyObject> <MyObject> <PropA>A3</PropA

Need a class/structure to serialize JSON in VB.net

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 12:14:15
问题 I am trying to figure out a class/struture to handle the following JSON format: { "ReturnData": [ { "id": "msg2DoesNotExistName", "value": "value 1", "userExists": 2 }, { "id": "msg2DoesNotExistName", "value": "Value 2", "userExists": 2 } ], "SetValue": [ { "id": "msg2DoesNotExistName", "value": "value 1" }, { "id": "msg2DoesNotExistName", "value": "Value 2" } ] } I have tried (just the SetValue portion): <Serializable()> _ Public Class Stuff Public SetValue() As ArrayList End Class Public

How to Serialize/DeSerialize a Dictionary variable?

删除回忆录丶 提交于 2019-12-24 11:58:33
问题 I have a Dictionary variable, the program reads XML files, and then instantiates objects stored in the Dictionary variable by type for performance. I would like to store the Dictionary variable to memcache for reuse, but, because the Dictionary variable and instantiated objects are reference types, when I operate instantiated objects to change some value, the cache value of memcache also changed. Code like the following. Dictionary variable and XPathNavigator variable of class can't serialize

Is there a way of specifying what data of an object is passed to the serializer when it's being serialized?

北战南征 提交于 2019-12-24 11:54:24
问题 I'm serializing quite complex data-structures using native JSON.stringify of chrome(will switch to some serialization library later for cross-browser support). Most of the data can be looked upon as static, but some is dynamic. When constructing the data I'd like to be able to do something like var dynamicString=new String(); {a:"foo", b:dynamicString} Then set the primitive string-value of dynamicString later on. I'd like to do this rather than changing the property "b" of that object

Why readObject method must call defaultReadObject to preserve backward and forward compatibility

廉价感情. 提交于 2019-12-24 11:44:40
问题 I am going through Effective Java, item 75: If all instance fields are transient, it is technically permissible to dispense with invoking defaultWriteObject and defaultReadObject , but it is not recommended. Even if all instance fields are transient, invoking defaultWriteObject affects the serialized form, resulting in greatly enhanced flexibility. The resulting serialized form makes it possible to add nontransient instance fields in a later release while preserving backward and forward