deserialization

JSON to C# — list fields without sub-field names in json?

心不动则不痛 提交于 2019-12-23 09:50:29
问题 Using Json.net (Newtonsoft.json), how can I define a C# class (or classes) to handle the json below? The 'data' field appears to be a list of level/description sub-fields but note they are not preceded by field names. The 'error' field appears to be a list of error-number/error-message sub-fields but note, they too, are not preceded by field names. { "status": "error", "data": [ { "warning" : "your input was wrong" } ], "error": [ { "373": "Error description goes here" } ] } This class

how to serialize for android.location class?

别等时光非礼了梦想. 提交于 2019-12-23 09:34:13
问题 I'm trying to serialize my location class (using android.location class) but, it gives me an error! 11-21 21:25:37.337: W/System.err(3152): java.io.NotSerializableException: android.location So, I tried to extend the android.location.Location class. private class NewLocation extends Location implements Serializable { private String Provider; private double Latitude, Longitude, Altitude; private float bear; public NewLocation(Location l) { super(l); Provider = l.getProvider(); Latitude = l

Jackson 2.3.2: Issue with deserializing a Date despite of setting the date format to ObjectMapper

僤鯓⒐⒋嵵緔 提交于 2019-12-23 08:07:57
问题 I am using rest easy and want to serialize and deserialize dates. After creating my json provider, Serializing is working fine but deserializing is still not working. My JsonProvider class: @Provider @Produces(MediaType.APPLICATION_JSON) public class JsonProvider extends JacksonJaxbJsonProvider { public JsonProvider() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,

Null values for object properties de-serialized by WCF

空扰寡人 提交于 2019-12-23 08:07:31
问题 I have a WCF web service that used to work fine. Somewhere down the line it stopped and I cant tell why. The code and the interface never changed nor did the web.config (at least not in relation to the web services section). I have a class: [DataContract] public class QuizServiceArgs { [DataMember(IsRequired = true, Order = 1)] public int Category1 { get; set; } [DataMember(IsRequired = true, Order = 2)] public int Category2 { get; set; } [DataMember(IsRequired = true, Order = 3)] public int

How can I deserialize integer number to int, not to long?

谁说我不能喝 提交于 2019-12-23 07:49:47
问题 I'm using Json.NET to deserialize requests on the server-side. There is something like public object[] Values I need to put in values like 30.0 , 27 , 54.002 , and they need to be double 's and int 's. Json.NET has a deserialization property called FloatParseHandling , but there is no option like IntParseHandling . So the question is how can I deserialize integers to int ? 回答1: Your best bet is to deserialize into a typed model where the model expresses that Values is an int / int[] / etc. In

Jackson Deserializer for one custom field?

Deadly 提交于 2019-12-23 07:48:21
问题 I believe we need a custom deserializer to do something specific with one field on our class. It appears once I do this, I am now responsible for deserializing all the other fields. Is there a way to have Jackson deserialize all the fields except the one I am concerned with here? public class ThingDeseralizer extends StdDeserializer<Thing> {     @Override     public Thing deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {        ObjectCodec oc

How do I keep reading an endless stream with fail tolerance

纵饮孤独 提交于 2019-12-23 05:27:38
问题 Currently i'm working on an app that reads the stream from a Twitter api and parses it into objects. At the moment I read the stream and use ReadObject from DataContractJsonSerializer to make my objects. This works great!! HOWEVER: I'm kind of worried what would happen in the off chance my program catches up with the stream (internet slows down or w/e) and there is not enough data to parse...The method will probably throw an exception, but i want to wait for new data and then retry the same

Deserialize Json using C# with variable content

谁都会走 提交于 2019-12-23 05:17:17
问题 I'm reposting this question because someone marked it as duplicate but it's not, so I detailed more to avoid the confusion. I'm creating an API in c# that my WebApp can reach to get some data. In my web app, i have a view with a list of (let's say) products. For now i have a route that return all my products stored in Database. I would like now to add the ability for the webapp to make complexe filters. I would like to be able in the webApp or with Postman for exemple, to reach my route (let

Gson: How do I deserialize interface fields having class names?

给你一囗甜甜゛ 提交于 2019-12-23 05:08:53
问题 I am trying to deserialize a List of Research objects but I can't make it work. I know that I need a custom adapter to deserialize my object since I am using an interface in my Research class but I am unsure on how to implement it. I currently have a serializer which seems to work and saves the class type for desirialization. I've been using bits of code from this SO post to make the serializer: Gson deserialize interface to its Class implementation This is the JSON I'm working with: [ {

Deserializing WCF Message at Server

你。 提交于 2019-12-23 05:01:17
问题 I implemented a custom message inspector (via IDispatchMessageInspector) to intercept messages that are received on the server side of a WCF service so I can attempt to deserialize the message and apply some specific business logic. The problem I'm encountering is when I write the MessageBuffer's contents to a new MemoryStream and then try to deserialize, I get an error that says "The data at the root level is invalid. Line 1, position 1." I do know the data being passed in is valid as