serialization

When using Jackson, System.out.println(new ObjectMapper().readTree(jsonStringObject)); prints the JSON with random spaces in between keys and values

自古美人都是妖i 提交于 2021-02-17 05:15:32
问题 A very strange behavior. When I just print the System.out.println(jsonStringObject); it prints the JSON properly and well, but when I use Jackson's API, namely new ObjectMapper().readTree(jsonStringObject); it incorporates some random spaces. 回答1: A very strange behavior. Indeed. But see what the JsonNode class documentation says about the toString() method: Method that will produce developer-readable representation of the node; which may or may not be as valid JSON. If you want valid JSON

Newtonsoft JSON serialization for byte[] property [duplicate]

我与影子孤独终老i 提交于 2021-02-16 20:20:47
问题 This question already has answers here : How to serialize byte[] as simple JSON Array and not as base64 in JSON.net? (3 answers) Closed 3 years ago . public class MyClass { public byte[] Bytes{get;set;} } MyClass obj = new MyClass(); obj.Bytes = new byte[]{1,22,44,55}; string s_result = Newtonsoft.Json.JsonConvert.SerializeObject(obj); // my s_result looks like {"Bytes":"KQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="} I want result like "Bytes":"1,22,44,55" I did work around for this by

Datapoint Serialization

徘徊边缘 提交于 2021-02-16 15:39:22
问题 How can I only serializable DataPoints? I want save DataPoints to a file. [Serializable] class CIE { public List<DataPoint> CieDataPoint = new List<DataPoint>() ; } List<DataPoint> GetCieColorPoints(string filename, int count) { CIE cie = new CIE(); var data = new List<DataPoint>(); float cr = (float)Math.Sqrt(count); using (Bitmap bmp = new Bitmap(filename)) { int sx = (int)(bmp.Width / cr); int sy = (int)(bmp.Height / cr); float scx = 0.8f / bmp.Width; float scy = 0.9f / bmp.Height; for

Serializing Timespan in Dictionary<string, object> with Json.NET

主宰稳场 提交于 2021-02-16 14:21:46
问题 I have a property that is actually a Dictionary. And I keep many types in this dictionary like TimeSpans, DateTimes, etc. But serializing and deserializing TimeSpans are wrong and it deserializes as string. var dict = new Dictionary<string, object>(); dict.Add("int", 15); dict.Add("string", "foo"); dict.Add("timeSpan", new TimeSpan(1,1,1)); dict.Add("dateTime", DateTime.Now); var settings = new JsonSerializerSettings{ TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat =

“invalid type: map, expected a sequence” when deserializing a nested JSON structure with Serde

点点圈 提交于 2021-02-16 10:49:30
问题 I am trying to poll the GitHub API for issues and print them out. To do so, I need to deserialize a nested JSON structure that I receive from a cURL GET request. I am trying to get the url for all the objects in the items array: { "total_count": 4905, "incomplete_results": false, "items": [ { "url": "https://api.github.com/repos/servo/saltfs/issues/789", "repository_url": "https://api.github.com/repos/servo/saltfs", "labels_url": "https://api.github.com/repos/servo/saltfs/issues/789/labels{

“invalid type: map, expected a sequence” when deserializing a nested JSON structure with Serde

左心房为你撑大大i 提交于 2021-02-16 10:48:10
问题 I am trying to poll the GitHub API for issues and print them out. To do so, I need to deserialize a nested JSON structure that I receive from a cURL GET request. I am trying to get the url for all the objects in the items array: { "total_count": 4905, "incomplete_results": false, "items": [ { "url": "https://api.github.com/repos/servo/saltfs/issues/789", "repository_url": "https://api.github.com/repos/servo/saltfs", "labels_url": "https://api.github.com/repos/servo/saltfs/issues/789/labels{

Why deserialize XML into Object return null value?

谁都会走 提交于 2021-02-11 16:55:02
问题 I have a XML string like that: <?xml version="1.0" ?> <result> <vmeet_id>7121</vmeet_id> <username>MT_Hue_QuangBinh_QuangTri</username> <email></email> <begin_date>2010-04-21 08:53</begin_date> <expiry_date>2010-12-21 00:00</expiry_date> <point></point> <info>OK</info> </result> I want to deserialize it into an object, so I created this class: [Serializable] [XmlRoot(ElementName = "result", IsNullable = false)] public class UserInfo { [XmlAttribute("vmeet_id")] public int UserID { get; set; }

Why deserialize XML into Object return null value?

我是研究僧i 提交于 2021-02-11 16:54:47
问题 I have a XML string like that: <?xml version="1.0" ?> <result> <vmeet_id>7121</vmeet_id> <username>MT_Hue_QuangBinh_QuangTri</username> <email></email> <begin_date>2010-04-21 08:53</begin_date> <expiry_date>2010-12-21 00:00</expiry_date> <point></point> <info>OK</info> </result> I want to deserialize it into an object, so I created this class: [Serializable] [XmlRoot(ElementName = "result", IsNullable = false)] public class UserInfo { [XmlAttribute("vmeet_id")] public int UserID { get; set; }

Serializing a 2D array with JsonUtility

微笑、不失礼 提交于 2021-02-11 14:59:55
问题 so Im tryint to save some data with the Unity JSON utilities but Im having some trobles. I have a World class that inside has some parameters like Width Height etc, and a 2D array of "Tiles", that its another class Reduced version: public class World { [SerializeField] private Tile[,] tiles; public Tile[,] Tiles { get { return tiles; } protected set { } } [SerializeField] private int width; public int Width { get { return width; } } [SerializeField] private int height; public int Height { get

How can I change the property name of a serialized entity with toJSON?

南楼画角 提交于 2021-02-11 14:01:11
问题 I want to serialize a property with a different name than it has in the entity. @Entity() export class MyEntity { // This should be serialized with name_column in JSON @Column() name: string } When I call classToPlain I want the property name to be serialized to name_column : classToPlain(myEntity) // returns: {name: 'my name'} // should be: {name_column: 'my name'} 回答1: Is there a specific reason you are using json-typescript-mapper instead of class-transformer, which is natively supported