json-serialization

Make names of named tuples appear in serialized JSON responses

好久不见. 提交于 2020-12-28 13:20:41
问题 Situation : I have multiple Web service API calls that deliver object structures. Currently, I declare explicit types to bind those object structures together. For the sake of simplicity, here's an example: [HttpGet] [ProducesResponseType(typeof(MyType), 200)] public MyType TestOriginal() { return new MyType { Speed: 5.0, Distance: 4 }; } Improvement : I have loads of these custom classes like MyType and would love to use a generic container instead. I came across named tuples and can

Make names of named tuples appear in serialized JSON responses

倖福魔咒の 提交于 2020-12-28 13:13:31
问题 Situation : I have multiple Web service API calls that deliver object structures. Currently, I declare explicit types to bind those object structures together. For the sake of simplicity, here's an example: [HttpGet] [ProducesResponseType(typeof(MyType), 200)] public MyType TestOriginal() { return new MyType { Speed: 5.0, Distance: 4 }; } Improvement : I have loads of these custom classes like MyType and would love to use a generic container instead. I came across named tuples and can

Make names of named tuples appear in serialized JSON responses

早过忘川 提交于 2020-12-28 13:13:15
问题 Situation : I have multiple Web service API calls that deliver object structures. Currently, I declare explicit types to bind those object structures together. For the sake of simplicity, here's an example: [HttpGet] [ProducesResponseType(typeof(MyType), 200)] public MyType TestOriginal() { return new MyType { Speed: 5.0, Distance: 4 }; } Improvement : I have loads of these custom classes like MyType and would love to use a generic container instead. I came across named tuples and can

AspNet Core - input/output JSON serialization settings at Controller Level

拟墨画扇 提交于 2020-03-21 17:58:09
问题 My application requires the (almost default) JSON serialization settings: services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddJsonOptions(options => { options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; options.SerializerSettings.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat; options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; }); For one controller only, I need to use a different naming strategy

How to parse a Java List of already parsed JSON into a Big JSON?

百般思念 提交于 2020-01-05 04:23:11
问题 I use Jackson to serialize/deserialize JSON . I have a List<String> in which all elements inside are already serialized in JSON format. I would like to generate a big JSON from that List . In other word, I have: List<String> a = new ArrayList<>(); a[0] = JSON_0 a[1] = JSON_1 ... a[N] = JSON_N And I would like to render: [ {JSON_0}, {JSON_1}, ... {JSON_N} ] What is the best way to do so using Jackson ? 回答1: Probably the simpler solution would be to create ArrayNode and use addRawValue method:

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

How do I serialize a C# anonymous type to a JSON string?

我与影子孤独终老i 提交于 2019-12-17 02:07:16
问题 I'm attempting to use the following code to serialize an anonymous type to JSON: var serializer = new DataContractJsonSerializer(thing.GetType()); var ms = new MemoryStream(); serializer.WriteObject(ms, thing); var json = Encoding.Default.GetString(ms.ToArray()); However, I get the following exception when this is executed: Type '<>f__AnonymousType1`3[System.Int32,System.Int32,System.Object[]]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all

What is equivalent code settings for @JSonIgnore annotation?

别说谁变了你拦得住时间么 提交于 2019-12-07 05:44:04
问题 I'm new to Java and Jackson and a lot of other technologies which I try to use, so I'd appreciate a detailed answer. Is there a way to prevent one or more fields from being serialized using Jackson into a JSON String_like format, but without using any kind of JSON annotations? Something like: mapper.getSerializationConfig().something(ignore("displayname")) if you know what I mean. My object is an instance of a class that extends another one, and implements one interface also so on, so the

What is equivalent code settings for @JSonIgnore annotation?

佐手、 提交于 2019-12-05 11:04:49
I'm new to Java and Jackson and a lot of other technologies which I try to use, so I'd appreciate a detailed answer. Is there a way to prevent one or more fields from being serialized using Jackson into a JSON String_like format, but without using any kind of JSON annotations? Something like: mapper.getSerializationConfig().something(ignore("displayname")) if you know what I mean. My object is an instance of a class that extends another one, and implements one interface also so on, so the fields come from an hierarchy of classes. I need the JSON representation for that object but containing