serialization

Mixing MarshalByRefObject and Serializable

 ̄綄美尐妖づ 提交于 2019-12-30 04:46:06
问题 Various sources explain that When an object derives form MarshalByRefObject, an object reference will be passed from one application domain to another rather than the object itself. When an object is marked with [Serializable], the object will be automatically serialized, transported from one application domain to another and then deserialized to produce an exact copy of the object in the second application domain. Note then that while MarshalByRefObject passes a reference, [Serializable]

Flask Marshmallow/SqlAlchemy: Serializing many-to-many relationships

点点圈 提交于 2019-12-30 04:45:07
问题 I'm building a small REST api using Flask, flask-sqlalchemy and flask-marshmallow. For some requests I'd like to return a json serialized response consisting of my sqlalchemy objects. However I cant get the serialization to work with eagerly loaded sqlalchemy objects when using many-to-many relationships / secondary tables. Here is a simple example, more or less copy/pasted from flask-marshmallow docs: from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_marshmallow

Copy object properties: reflection or serialization - which is faster?

主宰稳场 提交于 2019-12-30 04:34:25
问题 I have two objects of the same type and need to copy property values from one object to another. There are two options: Use reflection, navigate through the properties of the first object and copy the values. Serialize the first object and deserialize a copy. Both work for my requirement, the question is which do I better use in the terms of speed (cost)? Example class Person { public int ID { get; set; } public string Firsthand { get; set; } public string LastName { get; set; } public int

Configuring the .NET WCF UTF-8 deserializer to modify/discard non-shortest form chars instead of throwing an exception?

半腔热情 提交于 2019-12-30 04:05:30
问题 We have a SOAP web service hosted via WCF. One of the clients we receive data from occasionally encodes UTF-8 using non-shortest form (See http://www.unicode.org/versions/corrigendum1.html for a bit of info on this). It's not easy to modify the client because these non-shortest form characters are not being encoded by our code. Instead we'd like to edit the WCF service to discard these characters, replace them with other placeholder char, or even accept the non-shortest form characters. Any

Best practice to Serialize java.time.LocalDateTime (java 8) to js Date using GSON

旧街凉风 提交于 2019-12-30 03:58:07
问题 In our recent project we use java 8. I need to serialize java.time.LocalDateTime to java script Date format. Currently what I did was define a custom serializer to convert LocalDateTime to timestamp. public class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime> { @Override public JsonElement serialize(LocalDateTime localDateTime, Type type, JsonSerializationContext jsonSerializationContext) { Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant(); Date date

How to serialize ANY object into a string?

旧街凉风 提交于 2019-12-30 03:19:23
问题 I'm running into an issue where my JSON serializer is failing randomly due to the character < showing up from time to time. I can't nail down where this is coming from and I want to - on exception - reserialize using a different method so I can see a full representation of the offending object. Is there any way to do this? My current code: // data is of type 'object' serialized = JsonConvert.SerializeObject(data, new JsonSerializerSettings() { Error = delegate(object sender, ErrorEventArgs

Find path to offending non-Serializable member variable

人走茶凉 提交于 2019-12-30 03:16:07
问题 In Java, Serialization makes reading and writing objects to streams REALLY easy. For instance, the following code snippet is mostly all it takes to write objects to a stream: ObjectOutputStream oos = ... //Initialize your output stream Object toWrite = ... //Initialize what you want to write here oos.writeObject(toWrite); //Writes the object to the stream oos.flush(); This will work just fine, provided that toWrite 's class implements the Serializable interface, AND that all of toWrite 's non

How to serialize a generic class in Java?

ⅰ亾dé卋堺 提交于 2019-12-30 03:10:49
问题 I have started to read about serialization in Java and little bit in other languages too, but what if I have a generic class and I want to save a instance of it to file. code example public class Generic<T> { private T key; public Generic<T>() { key = null; } public Generic<T>(T key) { this.key = key; } } Whats the best way to save this kind of Object? (Of course there is more in my real ceneric class, but I'm just wondering the actual idea.) 回答1: You need to make generic class Serializable

How to serialize a generic class in Java?

安稳与你 提交于 2019-12-30 03:10:05
问题 I have started to read about serialization in Java and little bit in other languages too, but what if I have a generic class and I want to save a instance of it to file. code example public class Generic<T> { private T key; public Generic<T>() { key = null; } public Generic<T>(T key) { this.key = key; } } Whats the best way to save this kind of Object? (Of course there is more in my real ceneric class, but I'm just wondering the actual idea.) 回答1: You need to make generic class Serializable

Gson serialize POJO with root value included?

送分小仙女□ 提交于 2019-12-30 01:40:07
问题 I'm having a problem serializing an object using Gson. @XmlRootElement class Foo implements Serializable { private int number; private String str; public Foo() { number = 10; str = "hello"; } } Gson will serialize this into a JSON {"number":10,"str":"hello"} . However, I want it to be {"Foo":{"number":10,"str":"hello"}} , so basically including the top level element. I tried to google a way to do this in Gson, but no luck. Anyone knows if there is a way to achieve this? Thanks! 回答1: You need