deserialization

Jackson JSON Deserialization: array elements in each line

﹥>﹥吖頭↗ 提交于 2020-05-10 07:41:08
问题 I am using Jackson and would like to pretty-print JSON such that each element in arrays goes to each line, like: { "foo" : "bar", "blah" : [ 1, 2, 3 ] } Setting SerializationFeature.INDENT_OUTPUT true only inserts newline characters for object fields, not array elements, printing the object in this way instead: { "foo" : "bar", "blah" : [1, 2, 3] } Does anyone know how to achieve this? Thanks! 回答1: You could extend the DefaultPrettyPrinter and override the methods beforeArrayValues(…) and

How can I return FlightOfferSearch and FlightOrder objects as JSON?

≡放荡痞女 提交于 2020-04-30 09:21:07
问题 If I try to return FlightOfferSearch[] or FlightOrder objects from a handler method of my Spring Boot REST Controller, they don't seem to get serialized correctly like simpler POJOs I've worked with before where Jackson handled JSON serialization. My code (actual API calls mostly identical to the SDK github example): import com.amadeus.Amadeus; import com.amadeus.Params; import com.amadeus.exceptions.ResponseException; import com.amadeus.resources.FlightOfferSearch; import com.amadeus

Deserializing a PHP serialized string in node js

社会主义新天地 提交于 2020-04-30 06:38:06
问题 I have a PHP serialized string which I was unserializing using php-serialize or 'locutus/php/var/unserialize' in Node js. "a:2:{s:3:\"$or\";a:1:{i:0;a:1:{s:4:\"$and\";a:1:{i:0;a:1:{s:20:\"attributes.FIRSTNAME\";C:18:\"MongoDB\\BSON\\Regex\":49:{a:2:{s:7:\"pattern\";s:2:\"^a\";s:5:\"flags\";s:1:\"i\";}}}}}}s:4:\"$and\";a:1:{i:0;a:1:{s:3:\"$or\";a:2:{i:0;a:1:{s:8:\"batch_id\";a:1:{s:7:\"$exists\";b:1;}}i:1;a:1:{s:2:\"sc\";a:1:{s:3:\"$ne\";i:-2;}}}}}}" I am getting error when I try to

System.Text.Json - Deserialize nested object as string

感情迁移 提交于 2020-04-30 05:12:00
问题 I'm trying to use the System.Text.Json.JsonSerializer to deserialize the model partially, so one of the properties is read as string that contains the original JSON. public class SomeModel { public int Id { get; set; } public string Name { get; set; } public string Info { get; set; } } The example code var json = @"{ ""Id"": 1, ""Name"": ""Some Name"", ""Info"": { ""Additional"": ""Fields"", ""Are"": ""Inside"" } }"; var model = JsonSerializer.Deserialize<SomeModel>(json); should produce the

System.Text.Json - Deserialize nested object as string

偶尔善良 提交于 2020-04-30 05:11:37
问题 I'm trying to use the System.Text.Json.JsonSerializer to deserialize the model partially, so one of the properties is read as string that contains the original JSON. public class SomeModel { public int Id { get; set; } public string Name { get; set; } public string Info { get; set; } } The example code var json = @"{ ""Id"": 1, ""Name"": ""Some Name"", ""Info"": { ""Additional"": ""Fields"", ""Are"": ""Inside"" } }"; var model = JsonSerializer.Deserialize<SomeModel>(json); should produce the

Deserialize date attribute of json into LocalDate

可紊 提交于 2020-04-29 12:50:51
问题 I am trying to de-serialize date attribute in json of format "2018-05-27" using Gson. I want date to be in LocalDate format after de-serialization. For json input : { "id" : 1, "name" : "test", "startDate" : "2018-01-01", "endDate" : "2018-01-05", } I am getting error for startDate and endDate : java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING 回答1: The way we can do this is : private static final Gson gson = new GsonBuilder().registerTypeAdapter(LocalDate.class, new

Passing Json information to object constructor when deserializing

不问归期 提交于 2020-03-26 15:13:10
问题 I have a Json file that is composed of nested serialized objects. When deserializing this file I get my nested object reconstructed as needed, doing the following: var SomeNestedObjects= JsonConvert.DeserializeObject<SomeNestedObjectsFormat>(File.ReadAllText(@"e:\file.json")); Now, everything works great because my system has a definition of all these nested object and the JsonConverter is therefore able to create and initialise the lot out of whatever is in that Json file. What I would like

Deserialize JSON-File with multiple datatypes for a key

北慕城南 提交于 2020-03-24 02:56:12
问题 I wanted to analyze Telegram-Chats so I exported a chat in JSON format and wanted to deserialize it into my analyzing software. { "id": 397910, "type": "message", "date": "2018-02-21T10:27:59", "edited": "1970-01-01T01:00:00", "from": "Username", "from_id": 39033284, "text": "Some Text" } So I've used this simple code to read the JSON List<JSONObject> jsonObjects = JsonConvert.DeserializeObject<List<JSONObject>>(File.ReadAllText(openFileDialog.FileName)); public class JSONObject { public int

Deserialize JSON to table

▼魔方 西西 提交于 2020-03-22 04:58:49
问题 I need to populate tables in ABAP from data received through an API. I'm using the following ABAP function to populate an existing ABAP table from json. The JSON is correct, and the Table contains corresponding tables within tables. /ui2/cl_json=>deserialize( EXPORTING json = lv_json CHANGING data = lt_abap ). Running this returns a blank lt_abap table. When changing the output to be a structure this works fine. But the problem is a need a TABLE, rather than a STRUCTURE for subsequent calls

Unable to deserialize java.awt.color using jackson deserializer

ぐ巨炮叔叔 提交于 2020-03-21 20:58:33
问题 public class TestJacksonColor { public static void main(String [] args) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); Color black = new Color(0, 0, 0); String json = objectMapper.writeValueAsString(black); Color backToObject = objectMapper.readValue(json, Color.class); } } The code attempts to take an java.awt.color class serialize it using jackson objectmapper. Take the resulting json string and deserialize it back to an java.awt.color class. However when doing the