json-deserialization

Remove empty JSON objects from an array in Jackson serialization

二次信任 提交于 2021-02-11 07:53:31
问题 I have a List in a Java Pojo class. That list contains some MyChildPojo objects which are not null but can have properties with null values. Example: MyChildPojo obj1 = new MyChildPojo(); MyChildPojo obj2 = new MyChildPojo(); I have added @JsonInclude(JsonInclude.Include.NON_EMPTY) on my MyChildPojo class so null properties will not be added while serializing the object. Now my final serialized output for the List object is: [ {}, {} ] I want to remove the complete List object in this case. I

Deserialize JSON and assign to model

时光毁灭记忆、已成空白 提交于 2021-02-10 18:33:55
问题 As part of my web api, I'm getting the following JSON returned. ["{\"InputType\":17,\"EngineSubType\":4,\"Filename\":\"targetFile.csv\",\"FileExtensionType\":\".csv\",\"IsLoadFile\":true,\"LoadContextId\":4121,\"ReportingDate\":\"2019-05-31T00:00:00\",\"IsSuccess\":false}"] What I'm wanting to do is grab the value next to Filename and assign it to my models Filename parameter. In my project I've created a unit test to experiment with grabbing that value, but each attempt I've making is

Json.NET: Different JSON schemas for a single property

泪湿孤枕 提交于 2021-02-10 18:01:01
问题 I'm working with a third-party API that plays fast and loose with its returned JSON objects. In C#, I'm trying to set up Json.NET to deserialize these JSON objects to classes, but I've run into a hitch: sometimes the same property name will be used with several different schemas, depending on context. Here's an example of the JSON data structure: { "examples": [{ "data": "String data", "type": "foo" }, { "data": { "name": "Complex data", "19": { "owner": "Paarthurnax" } }, "type": "complex" }

Json.NET: Different JSON schemas for a single property

*爱你&永不变心* 提交于 2021-02-10 17:59:45
问题 I'm working with a third-party API that plays fast and loose with its returned JSON objects. In C#, I'm trying to set up Json.NET to deserialize these JSON objects to classes, but I've run into a hitch: sometimes the same property name will be used with several different schemas, depending on context. Here's an example of the JSON data structure: { "examples": [{ "data": "String data", "type": "foo" }, { "data": { "name": "Complex data", "19": { "owner": "Paarthurnax" } }, "type": "complex" }

Spring JsonDeserializer not working for the type String

我的未来我决定 提交于 2021-02-10 04:56:11
问题 I have a requirement to strip off all the special characters and control characters from the fields of type String in any of the Objects. Deserializer was registered but never executes during the runtime for Strings . I tried adding the same as an annotation @JsonDeserialize(using = StringProcessorComponent.class) , but the same issue. It works for any other type like Date / Long . Please let me know if I am missing any. Here is my Deserializer. @JsonComponent public class

Cant deserialize object - Expected BEGIN_OBJECT but was STRING at line 1 column 1

江枫思渺然 提交于 2021-02-07 08:51:43
问题 First let me say, I have searched before posting, just cant find the answer. I'm having trouble de-serializing a JSON. It is a valid JSON (checked at http://jsonlint.com/) and it was produced with servicestack json serializer. I'm getting java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 Here is my JSON sent by the server: { "artistName": "", "pathInfo": "C:\\Users\\Unknown\\Desktop\\Audio Sketches\\Chill.mp3", "indexPos": 0, "messageType": "song" } How

Cant deserialize object - Expected BEGIN_OBJECT but was STRING at line 1 column 1

五迷三道 提交于 2021-02-07 08:49:27
问题 First let me say, I have searched before posting, just cant find the answer. I'm having trouble de-serializing a JSON. It is a valid JSON (checked at http://jsonlint.com/) and it was produced with servicestack json serializer. I'm getting java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 Here is my JSON sent by the server: { "artistName": "", "pathInfo": "C:\\Users\\Unknown\\Desktop\\Audio Sketches\\Chill.mp3", "indexPos": 0, "messageType": "song" } How

How to deserialise enumeration with string representation?

落爺英雄遲暮 提交于 2021-02-04 07:31:30
问题 I would like to create a class, which has an enumeration as an attribute. This enumeration should have a string representation that shows up as human-readable value when dumping the instance of the class that uses the enum attribute as a JSON string. In the minimal working example below, I created three enumerations in three different ways. After the deserialization, each attribute shows us that it comes from an enumeration except the enumeration with a string representation. It is just a

How to deserialise enumeration with string representation?

我的未来我决定 提交于 2021-02-04 07:30:25
问题 I would like to create a class, which has an enumeration as an attribute. This enumeration should have a string representation that shows up as human-readable value when dumping the instance of the class that uses the enum attribute as a JSON string. In the minimal working example below, I created three enumerations in three different ways. After the deserialization, each attribute shows us that it comes from an enumeration except the enumeration with a string representation. It is just a

Google Gson treats every JSON local file as a string even when its not

落爺英雄遲暮 提交于 2021-02-02 09:55:39
问题 I am constantly getting Expected BEGIN_TYPE but was STRING at line 1 column 1 path $ error. I've read about that error, but I am experiencing something different. When I try to use gson.fromJson() on a JSON string I've created in my app it compiles fine. ArrayList<MyCar> cars = new ArrayList<>(); cars.add(new MyCar()); cars.add(new MyCar()); String json = gson.toJson(cars); This compiles. Type carList = new TypeToken<ArrayList<MyCar>>(){}.getType(); ArrayList<MyCar> myCars = gson.fromJson