jsonserializer

How to invoke another serializer from a custom Gson JsonSerializer?

为君一笑 提交于 2019-12-21 07:18:08
问题 I have my custom class User : class User { public String name; public int id; public Address address; public Timestamp created; } I'm now creating a custom JsonSerializer for User.class: @Override public JsonElement serialize(User src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); obj.addProperty("name", src.name); obj.addProperty("id", src.id); obj.addProperty("address", src.address.id); // Want to invoke another JsonSerializer (TimestampAdapter) for

Is there any way to JSON.NET-serialize a subclass of List<T> that also has extra properties?

点点圈 提交于 2019-12-18 04:42:24
问题 Ok, we're using Newtonsoft's JSON.NET product, which I really love. However, I have a simple class structure for hierarchical locations that look roughly like this... public class Location { public string Name{ get; set; } public LocationList Locations{ get; set; } } // Note: LocationList is simply a subclass of a List<T> // which then adds an IsExpanded property for use by the UI. public class LocationList : List<Location> { public bool IsExpanded{ get; set; } } public class RootViewModel {

Is there any way to JSON.NET-serialize a subclass of List<T> that also has extra properties?

情到浓时终转凉″ 提交于 2019-12-18 04:42:06
问题 Ok, we're using Newtonsoft's JSON.NET product, which I really love. However, I have a simple class structure for hierarchical locations that look roughly like this... public class Location { public string Name{ get; set; } public LocationList Locations{ get; set; } } // Note: LocationList is simply a subclass of a List<T> // which then adds an IsExpanded property for use by the UI. public class LocationList : List<Location> { public bool IsExpanded{ get; set; } } public class RootViewModel {

How to use Gson to serialize objects in android?

孤街浪徒 提交于 2019-12-17 20:36:57
问题 I want to send 2 objects to Java server from Android client using socket (as I am developing a Remote PC). AndroidClient.java public class MainActivity extends Activity{ Socket client; ObjectOutputStream oos; OutputStream os; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SendObj so=new SendObj(); so.execute(); } class SendObj extends AsyncTask<Void, Void, Void>{ @Override protected Void doInBackground

JObject.Parse vs JsonConvert.DeserializeObject

≡放荡痞女 提交于 2019-12-17 15:24:46
问题 What's the difference between JsonConvert.DeserializeObject and JObject.Parse? As far as I can tell, both take a string and are in the Json.NET library. What kind of situation would make one more convenient than the other, or is it mainly just preference? For reference, here's an example of me using both to do exactly the same thing - parse a Json string and return a list of one of the Json attributes. public ActionResult ReadJson() { string countiesJson = "{'Everything':[{'county_name':null,

JsonInclude.Include.NON_DEFAULT not working with custom serializer

我只是一个虾纸丫 提交于 2019-12-14 01:19:37
问题 I want to both use a custom serializer and have the JsonInclude.Include.NON_DEFAULT designation be honored. When I don't use a custom serializer it is honored but when I do use a custom serializer it is not. This is Jackson 2.2.2. I do not presently have the option to switch to a newer version of Jackson. Here's a simple example that shows the problem: import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core

Json structure is returned empty, without property names and values when using Newtonsoft JsonConvert in FB C# client

妖精的绣舞 提交于 2019-12-13 17:22:23
问题 I'm working on asp.net mvc 4 application which uses Facebook C# SDK (6.0.10.0) and Newtonsoft.Json (4.5.0.0). Request with FacebookClient returns expando object: [Authorize] public ActionResult GetFbData(string path = "me"){ var expando = this.fb.Get(path); return Json(expando); } Returned Json looks like: [{"Key":"id","Value":"100000xxxxxxxx"},{"Key":"name","Value":"John Doe"} ... ] I want to return it in format {id:100000xxxxxxx, name:"John Doe", ... } so I added this to the code which

@JsonSerialize not working

孤街醉人 提交于 2019-12-13 02:38:12
问题 In Spring/Hibernate project, in my entity class I have: package klab.finance.main.entity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import klab.backend.entity.postgres.base.BaseEntity; import klab.backend.utils.DateTimeUtils; import klab.backend.utils.JsonDateTime; import klab.backend.utils.json.LocalDateTimeToTimestampDeserializer; import klab

Convert JSON String from Camel case to Pascal case using C#

試著忘記壹切 提交于 2019-12-12 19:06:32
问题 I'm having a JSON string, it has Key in the form of Camel-case but I need to convert the Key to Pascal-case. Actual JSON String string jsonString = "{\"personName\":{\"firstName\":\"Emma\",\"lastName\":\"Watson\"}}"; Expected JSON String : Needs to convert from the above JSON string. string jsonString = "{\"PersonName\":{\"FirstName\":\"Emma\",\"LastName\":\"Watson\"}}"; Kindly assist me how to convert this using C#. 回答1: Because I can't sleep. If you define the following static class of

sequential calls of methods asynchronously

风格不统一 提交于 2019-12-12 15:20:02
问题 I have a list of methods I am calling in a method, as follows: this.doOneThing(); someOtherObject.doASecondThing(); this.doSomethingElse(); When this is synchronous, they are executed one after the other, which is required. But now I have someOtherObject.doASecondThing() as asynchronous, and I might turn doOneThing as async too. I could use a callback and call that.doSomethingElse from inside the callback: var that = this; this.doOneThing( function () { someOtherObject.doASecondThing(function