serialization

Java Mysterious EOF exception with readObject

本小妞迷上赌 提交于 2020-01-24 02:16:09
问题 The following code produces an EOFException . Why is that? public static Info readInfoDataFromFile(Context context) { Info InfoData = null; FileInputStream fis = null; ObjectInputStream ois = null; Object object = null; if (context.getFileStreamPath("InfoFile.dat").exists()) { try { fis = context.openFileInput("InfoFile.dat"); ois = new ObjectInputStream(fis); Object temp; try { // here it throws EOF exception in while loop while ((temp = ois.readObject()) != null) { object = temp; } } catch

Custom XML-element name for base class field in serialization

允我心安 提交于 2020-01-24 00:30:09
问题 How can I change XML-element name for field inherited from base class while doing serialization? For example I have next base class: public class One { public int OneField; } Serialization code: static void Main() { One test = new One { OneField = 1 }; var serializer = new XmlSerializer(typeof (One)); TextWriter writer = new StreamWriter("Output.xml"); serializer.Serialize(writer, test); writer.Close(); } I get what I need: <?xml version="1.0" encoding="utf-8"?> <One xmlns:xsi="http://www.w3

How can I pass a variable from a ASP website to a desktop application?

假如想象 提交于 2020-01-23 19:47:08
问题 I am trying to pass a variable from an asp project (written in c#) to a desktop c# application. I know using Javascript you can use a JavaScriptSerializer, but is there an equivalent for asp? 回答1: Depends on what you want to send back to the app or what is already being sent back by the server. i.e. let's say the result of a web page request were the "parameters" you speak of (you're not very clear, in the context of http and web communications). An ASP page can pass back the data to an app

How can I serialize a custom object that has a Context as a private member using Gson?

China☆狼群 提交于 2020-01-23 17:44:05
问题 I have an ArrayList of custom objects that I'm trying to store to disk as a JSON String using Gson. This works great for my objects that just contain basic types of data like Strings, but one class I have has a private member that stores the Activity's Context. When I try to serialize this class using Gson, I get the following Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxx.xxxx/com.xxxx.xxxx.MainActivity}: java.lang.SecurityException: Can't make method

Deserialization issue using a custom resolver with IDictionary<Mycustomclass, List<string>>

橙三吉。 提交于 2020-01-23 08:18:04
问题 Problem: I have a class Foo containing an IDictionary<MyCustomClass, List<string>> . I am using a custom ContractResolver as shown in this answer so that my dictionary will serialize as an array of objects containing "Key" and "Value" properties. That part works fine. However, when I try to deserialize the JSON back into Foo using the same resolver, I get an error as shown below. Error: Run-time exception (line 46): Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'System

serialize/deserialize a LinkedHashMap (android) java

一笑奈何 提交于 2020-01-23 07:35:29
问题 So i want to pass a LinkedHashMap to an intent. //SEND THE MAP Intent singlechannel = new Intent(getBaseContext(),singlechannel.class); singlechannel.putExtra("db",shows1);//perase to startActivity(singlechannel); //GET THE MAP LinkedHashMap<String,String> db = new LinkedHashMap<String,String>(); db=(LinkedHashMap<String,String>) getIntent().getSerializableExtra("db"); This one Worked Like a charm with HashMap. But with LinkedHashMap i got a problem i got a runtime error here db=

Executing a custom SQL query over WCF

筅森魡賤 提交于 2020-01-23 03:57:05
问题 I use WCF service with ORACLE and SQL Server. Then I need "generic" solution. I need built a WCF method to essentially execute a custom SQL string and return the reader results. This is not a great practice and is probably best avoided, it kind of breaks the whole point of the WCF service, but in my case this need have to be done. I don't want neither cannot WCF Data Service neither another technology or protocol. Only WCF service (SOAP). Any good practices about it? Maybe List<List<string>>

How to use custom serialization during .NET remoting?

折月煮酒 提交于 2020-01-22 22:48:52
问题 I've written a custom serialization routine that does not use ISerializable or the SerialzableAttribute to save my objects to a file. I also remote these same objects and would like to use the same serialization technique. However, I don't want to implement ISerializable because my serialization method is completely decoupled from my objects (and I'd like for it to stay that way). Is there an easy way (possibly with remoting sinks) where I can take a stream and write bytes to it and on the

Deserialize jQuery Serialized Form

我怕爱的太早我们不能终老 提交于 2020-01-22 20:41:05
问题 I'm trying to pass form inputs into a WebMethod and doing something. I used jQuery Serilize. <script type="text/javascript"> $.fn.serializeNoViewState = function () { return this.find("input,textarea,select,hidden") .not("[type=hidden][name^=__]") .serialize(); } $(function () { $("#Button1").click(function (e) { var res = $("#myform").serializeNoViewState(); var jsonText = JSON.stringify({ bject: res }); $.ajax({ type: "POST", url: "Default.aspx/Test", data: jsonText, contentType:

Enforcing serializable from an interface without forcing classes to custom serialize in C#

左心房为你撑大大i 提交于 2020-01-22 17:43:39
问题 I have an interface that defines some methods I would like certain classes to implement. public interface IMyInterface { MethodA; MethodB; } Additionally I would like all classes implementing this interface to be serializable. If I change the interface definition to implement ISerializable as below...: public interface IMyInterface : ISerializable { MethodA; MethodB; } ...all classes must now explicitly implement serialization as far as I am aware, since if you implement ISerializable you