deserialization

Conversion between JSON with wrapped structure and pojo with flattended structure

我的未来我决定 提交于 2021-01-27 07:33:38
问题 I have a JSON structure that incorporates a wrapping level that I don't have in my POJOs. Like so: JSON: { "category1": { "cat1Prop1": "c1p1", "cat1Prop2": "c1p2", "cat1Prop3": "c1p3" }, "category2": { "cat2Prop1": "c2p1", "cat2Prop2": "c2p2" }, "category3": { "cat3Prop1": "c3p1", "cat3Prop2": "c3p2", "cat3Prop3": "c3p3" }, "category4": { "cat4Prop1": "c4p1" } } POJO: public class MyPojo { private String cat1Prop1; private String cat1Prop2; private String cat1Prop3; private String cat2Prop1;

Conversion between JSON with wrapped structure and pojo with flattended structure

不问归期 提交于 2021-01-27 07:30:47
问题 I have a JSON structure that incorporates a wrapping level that I don't have in my POJOs. Like so: JSON: { "category1": { "cat1Prop1": "c1p1", "cat1Prop2": "c1p2", "cat1Prop3": "c1p3" }, "category2": { "cat2Prop1": "c2p1", "cat2Prop2": "c2p2" }, "category3": { "cat3Prop1": "c3p1", "cat3Prop2": "c3p2", "cat3Prop3": "c3p3" }, "category4": { "cat4Prop1": "c4p1" } } POJO: public class MyPojo { private String cat1Prop1; private String cat1Prop2; private String cat1Prop3; private String cat2Prop1;

Custom deserialization of List using Jackson

一笑奈何 提交于 2021-01-21 05:24:24
问题 I am trying to write a custom deserializer in order to trim down a big set of data I receive from somewhere else. I return a List of custom objects from the deserializer. My question is, how do I do that, if this is my custom deserializer : public class MyCustomDeserializer extends JsonDeserializer<List<CustomClass>> { ... } I certainly can't do this : final SimpleModule module = new SimpleModule(); module.addDeserializer(List<CustomClass>.class, new MyCustomDeserializer()); Will something

Custom deserialization of List using Jackson

不羁岁月 提交于 2021-01-21 05:24:07
问题 I am trying to write a custom deserializer in order to trim down a big set of data I receive from somewhere else. I return a List of custom objects from the deserializer. My question is, how do I do that, if this is my custom deserializer : public class MyCustomDeserializer extends JsonDeserializer<List<CustomClass>> { ... } I certainly can't do this : final SimpleModule module = new SimpleModule(); module.addDeserializer(List<CustomClass>.class, new MyCustomDeserializer()); Will something

json.net: DateTimeStringConverter gets an already DateTime converted object in ReadJson()

偶尔善良 提交于 2021-01-13 09:35:27
问题 Prerequisites: JSON.Net 11.0.2 I need to store the UTC DateTime round-trip date/time pattern via a JSON based REST-API. string utcTimestamp = DateTime.UtcNow.ToString( "o" ); // 2018-11-27T22:35:32.1234567Z So I wrote myself a DateTimeStringConverter to ensure no local culture information gets involved. class DateTimeStringConverter: JsonConverter<DateTime> { public override void WriteJson( JsonWriter writer, DateTime value, JsonSerializer serializer ) { string convertedValue = value.ToString

Deserializing complex nested java objects from JSON [closed]

爱⌒轻易说出口 提交于 2021-01-05 11:53:07
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . Improve this question So I have a java class Workspace that has field of type List of Product which contains field of type List of Module which contains field of type List with Objects. So I have like 3 levels nested objects with lists. What is the most painless way to deal with

Deserializing complex nested java objects from JSON [closed]

落爺英雄遲暮 提交于 2021-01-05 11:52:36
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . Improve this question So I have a java class Workspace that has field of type List of Product which contains field of type List of Module which contains field of type List with Objects. So I have like 3 levels nested objects with lists. What is the most painless way to deal with

Deserializing xml, including namespace

我只是一个虾纸丫 提交于 2021-01-02 06:17:23
问题 I am trying to deserialize some XML and I can't get the namespace / xsi:type="Model" to work. If xsi:type="Model" is left out of the XML it works, but it has to be there. If I leave the namespace out of my Model, I get an error, if I rename it, I get an empty list. XML <Vehicles xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Vehicle xsi:type="Model"> <Id>238614402</Id> </Vehicle> <Vehicle xsi:type="Model"> <Id>238614805</Id> </Vehicle> <

Deserializing xml, including namespace

风流意气都作罢 提交于 2021-01-02 06:15:26
问题 I am trying to deserialize some XML and I can't get the namespace / xsi:type="Model" to work. If xsi:type="Model" is left out of the XML it works, but it has to be there. If I leave the namespace out of my Model, I get an error, if I rename it, I get an empty list. XML <Vehicles xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Vehicle xsi:type="Model"> <Id>238614402</Id> </Vehicle> <Vehicle xsi:type="Model"> <Id>238614805</Id> </Vehicle> <

How do I replace the OData V4 default Json Serializer with NewtonSoft's Json Serializer?

时光毁灭记忆、已成空白 提交于 2020-12-29 04:07:09
问题 I have a class that contains a List of DynamicObjects. I have a unit test that confirms that the Newtonsoft Json Serializer/Deserializer handles this correctly. However, the default OData Json Serializer/Deserializer does not. I implemented my own ODataEdmTypeDeserializer like this: public class JsonODataEdmTypeDeserializer : ODataEdmTypeDeserializer { public JsonODataEdmTypeDeserializer(ODataPayloadKind payloadKind) : base(payloadKind) { } public JsonODataEdmTypeDeserializer(ODataPayloadKind