json-deserialization

Deserialize an anonymous JSON array?

风格不统一 提交于 2020-03-21 11:30:07
问题 I got an anonymous array which I want to deserialize, here the example of the first array object [ { "time":"08:55:54", "date":"2016-05-27", "timestamp":1464332154807, "level":3, "message":"registerResourcePath ('', '/sap/bc/ui5_ui5/ui2/ushell/resources/')", "details":"","component":"sap.ui.ModuleSystem"}, {"time":"08:55:54","date":"2016-05-27","timestamp":1464332154808,"level":3,"message":"URL prefixes set to:","details":"","component":"sap.ui.ModuleSystem"}, {"time":"08:55:54","date":"2016

Deserialize json character as enumeration

泄露秘密 提交于 2020-02-19 07:30:06
问题 I have an enumeration defined with C#, where I'm storing it's values as characters, like this: public enum CardType { Artist = 'A', Contemporary = 'C', Historical = 'H', Musician = 'M', Sports = 'S', Writer = 'W' } I'm attempting to deserialize using JSON.NET, but the incoming JSON was written using the CHAR value (string) instead of the int value of the enumeration, like this: [{"CardType","A"},{"CardType", "C"}] Is it possible to define some kind of converter that will allow me to manually

Deserialize json character as enumeration

点点圈 提交于 2020-02-19 07:29:49
问题 I have an enumeration defined with C#, where I'm storing it's values as characters, like this: public enum CardType { Artist = 'A', Contemporary = 'C', Historical = 'H', Musician = 'M', Sports = 'S', Writer = 'W' } I'm attempting to deserialize using JSON.NET, but the incoming JSON was written using the CHAR value (string) instead of the int value of the enumeration, like this: [{"CardType","A"},{"CardType", "C"}] Is it possible to define some kind of converter that will allow me to manually

Testing custom JsonDeserializer

扶醉桌前 提交于 2020-02-06 08:03:46
问题 I am trying to write a unit test to a custom deserializer that is instantiated using a constructor with an @Autowired parameter and my entity marked with @JsonDeserialize. public class MyDeserializer extends JsonDeserializer<MyEntity> { private final MyBean bean; // no default constructor @Autowired public MyDeserializer(MyBean bean){ this.bean = bean } ... } @JsonDeserialize(using = MyDeserializer.class) public class MyEntity{...} It works fine in my integration tests where a MockMvc brings

Testing custom JsonDeserializer

蓝咒 提交于 2020-02-06 08:03:05
问题 I am trying to write a unit test to a custom deserializer that is instantiated using a constructor with an @Autowired parameter and my entity marked with @JsonDeserialize. public class MyDeserializer extends JsonDeserializer<MyEntity> { private final MyBean bean; // no default constructor @Autowired public MyDeserializer(MyBean bean){ this.bean = bean } ... } @JsonDeserialize(using = MyDeserializer.class) public class MyEntity{...} It works fine in my integration tests where a MockMvc brings

How to register custom TypeAdapter or JsonDeserializer with Gson in Retrofit?

家住魔仙堡 提交于 2020-02-06 07:30:06
问题 I am using Retrofit in my project and I need some custom deserialization with some of the responses that the API I use returns. Just for an example: I receive JSON like: { "status": "7 rows processed" } ( will be "0 rows processed" if request failed ) and I need to deserialize to an object like: @Getter @RequiredArgsConstructor public static class Result { private final boolean success; } I have created custom deserializer: public class ResultDeserializer implements JsonDeserializer<Result> {

Newtosoft Json Deserialization: How to throw an error if/when the given json string has MORE properties than necessary?

折月煮酒 提交于 2020-02-05 05:31:32
问题 Assuming we have the following class: public class Foo { public long Id { get; set; } } How can we tell newtonsoft json to throw a tantrum if a given json-string is: { "Id": 10, "SomethingIrrelevant": "Foobar" } In other words we want the deserialization to be ultra-strict and throw a tantrum when it detects anything fishy of this sort taking place. 回答1: Use MissingMemberHandling.Error for your JsonSerializerSettings : var deserialized = JsonConvert.DeserializeObject<Foo>(jsonString, new

Is there an easy way to make Gson skip a field if there's an error deserializing it?

↘锁芯ラ 提交于 2020-02-04 05:26:24
问题 I'm trying to deserialize some data with Gson (Java) and the API I'm pulling data from sometimes has data of the wrong type in a field. I.e. if I'm expecting an array of String types, it might encounter a Boolean . Now I realize these are my current options: Always ignore the field from deserialization Create a custom TypeAdapter to do the deserialization and the catch the error and do something (like set the field to null ) However I'm asking if there's another way to easily make it so if

How to write a MassTransit Json Deserializer for Azure Services

你离开我真会死。 提交于 2020-02-02 05:32:40
问题 here it is how I am publishing to an object to event grid. I want to be able to use the azure service bus to listen to it. public void Publicar<T>(T model, string operation, string entity) { _nomeEvento = entity + operation; Boolean.TryParse(Configuration["EventGridConfig:Enabled"], out var eventGridIsActive); if (!eventGridIsActive) return; var primaryTopicKey = Configuration["EventGridConfig:AcessKey"]; var primaryTopic = Configuration["EventGridConfig:Endpoint"]; var primaryTopicHostname =

How to deserialize / serialize type Geometry in spring boot?

試著忘記壹切 提交于 2020-01-25 09:21:19
问题 I have an entity with attributes of type MultiPolygon and Point; so I'm making a get request but this is returning a SerializationException. I researched it and saw that I have to put some notes, create a configuration class and put the corresponding dependency in pom.xml. Follow as I did below: Entity: package com.zxventures.model; @Entity @Table(name = "pdv") public class PDV implements Serializable { private static final long serialVersionUID = 1L; @Column(name="coverage_area")