json-deserialization

How to deserialize a float value with a localized decimal separator with Jackson

爷,独闯天下 提交于 2019-12-19 03:12:58
问题 The input stream I am parsing with Jackson contains latitude and longitude values such as here: { "name": "product 23", "latitude": "52,48264", "longitude": "13,31822" } For some reason the server uses commas as the decimal separator which produces an InvalidFormatException . Since I cannot change the server output format I would like to teach Jackson's ObjectMapper to handle those cases. Here is the relevant code: public static Object getProducts(final String inputStream) { ObjectMapper

How use jackson ObjectMapper inside custom deserializer?

☆樱花仙子☆ 提交于 2019-12-18 13:01:23
问题 I try to write custom jackson deserializer. I want "look" at one field and perform auto deserialization to class, see example below: import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.mypackage.MyInterface; import com

What is deserialize and serialize in JSON?

混江龙づ霸主 提交于 2019-12-18 09:54:13
问题 I have seen the terms "deserialize" and "serialize" with JSON. What do they mean? (I'm new in JSON. Now, I need to use JSON for my Flash ActionScript 3.0. So I found one lib for JSON) 回答1: JSON is a format that encodes objects in a string. Serialization means to convert an object into that string , and deserialization is its inverse operation (convert string -> object) . When transmitting data or storing them in a file, the data are required to be byte strings, but complex objects are seldom

Json.Net calls property getter during deserialization of list, resulting in duplicate items

霸气de小男生 提交于 2019-12-17 19:39:48
问题 I'm using json.net to implement the memento pattern for a winform application. I'm using the memento to rollback an object on a failed database transaction. The problem I'm getting is that when deserializing the memento, the getter is called rather than the setter. Let me demonstrate: class MyClass { public int ID { get; set; } public string field1 { get; set; } public string field2 { get; set; } private List<SomeObject> _someObjects; public List<SomeObject> SomeObjects { get { if(

Custom deserializer only for some fields with json.NET

≡放荡痞女 提交于 2019-12-17 13:54:57
问题 I'm trying to deserialize some JSON: { "a":1, "b":25, "c":"1-7", "obj1":{ "a1":10, "b1":45, "c1":60 }, "obj2":[ { "a2":100, "b2":15, "c2":50 }, { "e2":"1,2,5-7", "f2":"1,3-5", "a2":25 } ] } I want to find a way to define a custom de-serialization only for some fields. In the following code, I separated the fields that need some attention (custom processing) and the ones that could be done automatically somehow. Is it possible to automatically deserialize the "normal" fields? (that don't need

How to map a dynamic JSON property to a fixed POJO field

删除回忆录丶 提交于 2019-12-13 19:20:03
问题 I have some json that i want to parse into pojo { "groups": [ { "g1": [ 1,2,5,6,7 ] }, { "g2": [ 2,3,48,79 ] } ] } Of course, "g1" and "g1" are the identifiers, so what i would imagine as pojos would be sth like class Container { List<Group> groups; } class Group { String id; List<Integer> values; } So it boils down to this question: How to use jackson to map a json-property to the pojo? 回答1: This kind of structure can be parsed using a custom deserializer added with the JsonDeserialize

error deserializing a Json string into a composite object

▼魔方 西西 提交于 2019-12-13 17:36:45
问题 I'm using Newtonsoft's Json.NET. Their documentation is not very helpful. What I need is to deserialize a json string into a C# object of a class of my authorship. The json string was never an object of this class, I got it using a WebRequest. I can't post the json string because It has over 34 thousand characters. Since the object uses a lot of composition, I tryed to generate all the classes needed myself. When I got a FormatException "Input string was not in a correct format." I thought

How to implement LibGDX Json.Serializable with default reader and custom writer

廉价感情. 提交于 2019-12-13 04:44:35
问题 I would like to use the default LibGDX Json deserializer to read in a JSON file, but implement my own method for writing the class back out to a JSON file. When I implement Json.Serializable, it forces me to implement both the read and write methods. How can I call the default deserializer in the read method? 回答1: I was looking for the same thing, finally this implemented read method worked for me, I hope it works for you too: @Override public void read(Json json, JsonValue jsonMap) { json

Parsing JSON Array to Java List Using Gson

好久不见. 提交于 2019-12-13 03:58:25
问题 What is the best way from the given JSON to generate List of SimpleTestClass type where there's a new SimpleTestClass object for the values in the recipients array in the JSON with code set as well. public class SimpleTestClass{ String code; String recipient; } JSON payload: { "code": 123, "recipients": [ "888888", "222222" ] } 回答1: If JSON structure does not fit to POJO model you need to write custom deserialiser or create a new POJO model which fits JSON and after deserialisation process

How to read dynamic returned JSON string in c#?

China☆狼群 提交于 2019-12-13 03:39:18
问题 I have a an Apple API which returns the Apple Device information using the SerialNumber/IMEI number and returns the JSON string. And have successfully have created a Classes using JSON to C# Class Converter and it works fine. But, the problem is, when i make a call for Out of Warranty [the device which has passed warranty it returns different JSON] device it returns JSON with different Key,Values hence the casting of RootObject fails. JSON 1: [For in Warranty Device] { "ios_info": {