serialize

GSON: serialize/deserialize object of class, that have registered type hierarchy adapter, using ReflectiveTypeAdapterFactory.Adapter

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: To be clear, let introduse some model: interface A { boolean isSomeCase(); } class AAdapter implements JsonSerializer<A> { public JsonElement serialize(A src, Type typeOfSrc, JsonSerializationContext context) { if (src.isSomeCase()) { /* some logic */ return result; } else { JsonObject json = new JsonObject(); JsonElement valueJson = <???>; // TODO serialize src like POJO json.add(src.getClass().getSimpleName(), valueJson); return json; } } } Gson gson = new GsonBuilder() .registerTypeHierarchyAdapter(A.class. new AAdapter()) .create(); How

Failed to serialize the response in Web API with Json

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working with ASP.NET MVC 5 Web Api. I want consult all my users. I write: api/users and I receipt this: "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'" In WebApiConfig, already I added this lines: HttpConfiguration config = new HttpConfiguration(); config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; But still doesn't work My

ORA-08177: can&#039;t serialize access for this transaction

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a very simple code using ADO.NET which throws ORA-08177 exception. I am not sure what's wrong with this. I am trying this on a windows vista machine which has oracle 32 bit client installed. My compile option for visual studio is set to x86 platform. Dim connection As OracleConnection = Nothing Dim transaction As OracleTransaction = Nothing Try connection = New OracleConnection("Data Source=ora10;User Id=userid;Password=passwd;") connection.Open() transaction = connection.BeginTransaction(IsolationLevel.Serializable) Dim inputStream

XmlSerializer change encoding

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using this code to Serialize XML to String : XmlWriterSettings xmlWriterSettings = new XmlWriterSettings { indent = true, Encoding = Encoding.UTF8 }; using (var sw = new StringWriter()) { using (XmlWriter xmlWriter = XmlWriter.Create(sw, xmlWriterSettings)) { XmlSerializer xmlSerializer = new XmlSerializer(moviesObject.GetType(), new XmlRootAttribute("category")); xmlSerializer.Serialize(xmlWriter, moviesObject); } return sw.ToString(); } The problem is that i get : <?xml version="1.0" encoding="utf-16"?> <category xmlns:xsi="http://www

Android: Attempted to serialize … Forgot to register a type adapter?\&quot;

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to convert HashMap to JSON using Gson . class ClassData { public String jsonString; public Class classType; } HashMap<String, ClassData> map = new HashMap<>(); void convert(){ new Gson().toJson(map); // throws } I am getting the next exception Attempted to serialize java.lang.Class: java.lang.String. Forgot to register a type adapter? 回答1: You need to implement your own custom serializer for ClassData, and then register it to your Gson Builder. public class ClassDataSerializerExample { static class ClassData { public String jsonString;

Protobuf-net possible recursion detected: serialize children and parents

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am new to serialization in general, and even newer to protobuf. Here is my problem, I have these classes: [ ProtoContract ] class Controle { [ ProtoMember ( 1 , AsReference = true )] public HashSet < Controle > ControlesInternes { get ; set ; } [ ProtoMember ( 2 )] public string TypeControle { get ; set ; } [ ProtoMember ( 3 )] public Dictionary < string , string > Attributs { get ; set ; } [ ProtoMember ( 4 )] public int Ligne { get ; set ; } [ ProtoMember ( 5 )] public string InnerText { get ; set ; } [ ProtoMember ( 6 )]

Cannot serialize member &lt;x&gt; because it is an interface

匿名 (未验证) 提交于 2019-12-03 01:00:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Follow on question from Error with explicit conversion when using CollectAs<> Code from WebMethod return client.Cypher .Match("(person:Person)") .Where((Person person) => person.Email == username) .OptionalMatch("(person)-[:SPEAKS]-(language:Language)") .OptionalMatch("(person)-[:CURRENT_LOCATION]-(country:Country)" .Return((person, language, country) => new ProfileObject { Person = person.As<Person>(), Language = language.CollectAs<Language>(), Country = country.CollectAs<Country>() }).Results.ToList(); Code from Country Class: public class

How do correctly use Jackson Mixin annotation to instantiate a third party class?

匿名 (未验证) 提交于 2019-12-03 01:00:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a third party library class (from Apache Axis) that I want to serialize by Jackson JSON: public class NonNegativeInteger extends BigInteger { public NonNegativeInteger(byte[] val) { super(val); checkValidity(); } // ctor public NonNegativeInteger(int signum, byte[] magnitude) { super(signum, magnitude); checkValidity(); } // ctor public NonNegativeInteger(int bitLength, int certainty, Random rnd) { super(bitLength, certainty, rnd); checkValidity(); } // ctor public NonNegativeInteger(int numBits, Random rnd) { super(numBits, rnd);

Json4s support for case class with trait mixin

匿名 (未验证) 提交于 2019-12-03 00:56:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to serialize scala case class using json4s with jackson support. But for scenarios where i am trying to mixin traits, it fails to serialize the class. Below is a code example. trait ISearchKey { var id:String = "" } When i execute below code i get empty curly brackets, no value serialized, but if i remove trait mixin then CrystalFieldInfo value gets serialized properly val fld = new CrystalFieldInfo("Field1") with ISearchKey fld.id = "Id1" implicit val formats = Serialization.formats(NoTypeHints) val ser = write[CrystalFieldInfo

2018小训―2017_“百度杯”CTF比赛_十月场_Login

匿名 (未验证) 提交于 2019-12-03 00:40:02
题目源:  https://www.ichunqiu.com/battalion?q=2725  i春秋上滴题目 小工具:  Burp Suite(抓包神器)、http://base64.xpcha.com/(base64在线解码网站)、https://tool.lu/coderunner/(php在线编写运行网站) 思路点用黄色加粗标记、操作点用绿色加粗标记。 解题的流程:     1.登录题,输username:admin password:admin没什么软用(前期各种尝试判断可能的题型), 检查源码, 在源码的最下面有发现,ps:一开始还真没看见藏在最小面的小惊喜,提醒审计的时候要确认你真的看全了。      尝试 username:test1 password:test1 ,登录成功!     2.就一个掀桌子的画面,检查源码,啥也没有。怀疑人生,,应用层的看完了,看看数据层有没有惊喜, 查看数据包 使用 BurpSuite抓包 (抓的是掀桌子的那个包,就是刷新掀桌子,截取数据包在BurpSuit里查看response)。      注意右边有个show:0返回,这是什么意思呢?状态标记吧,如果提交一个show:1会返回什么呢?     3. 更改数据包 的内容, 添加一项show: 1; (注意英文字符,冒号后面有一个空格)      在右边返回了一份源码。     4