jsonserializer

Jackson2 Java to Json array ignore field names when creating array

你说的曾经没有我的故事 提交于 2019-12-10 11:32:11
问题 I'm trying to create a Java REST endpoint which returns a JSON data array to be consumed by JQuery FLOT charting plugin. At a minimum, the JSON data for FLOT needs to be an array of numbers i.e. [ [x1, y1], [x2, y2], ... ] Given I have a List of Point objects in Java i.e. List<Point> data = new ArrayList<>(); where Point is defined as public class Point { private final Integer x; private final Integer y; public Point(Integer x, Integer y) { this.x = x; this.y = y; } ... } What methods or

Jackson deserializing into Map with an Enum Key, POJO Value

那年仲夏 提交于 2019-12-08 18:33:20
问题 I am trying to deserialize JSON into a Java POJO using Jackson. Without giving away confidential information, here is an example stack trace when ObjectMapper's deserialization fails: org.codehaus.jackson.map.JsonMappingException: Can not construct Map key of type com.example.MyEnum from String "coins": not a valid representation: Can not construct Map key of type com.example.MyEnum from String "coins": not one of values for Enum class My JSON looks like this: "foo": { "coins": null, ... }

How to deserialize variable size JSON string with variable names

久未见 提交于 2019-12-08 08:17:34
问题 Deserializing a small, fixed size, fixed structure, with fixed field names, JSON string is easy: Just define a class that contains all the fields (with correct types and names, all known at compile time). Deserializing a variable-size of repeating nested pairs, is somewhat more challenging but can be done with the help of a List<> inside the class. But what do I do when the name of the fields are unknown at compile time? e.g.: { "container":{ "GD01AB491103":{ "field_id1":11, "field_id2":12,

How to deserialize variable size JSON string with variable names

强颜欢笑 提交于 2019-12-06 22:53:28
Deserializing a small, fixed size, fixed structure, with fixed field names, JSON string is easy: Just define a class that contains all the fields (with correct types and names, all known at compile time). Deserializing a variable-size of repeating nested pairs, is somewhat more challenging but can be done with the help of a List<> inside the class. But what do I do when the name of the fields are unknown at compile time? e.g.: { "container":{ "GD01AB491103":{ "field_id1":11, "field_id2":12, "field_id3":13, "field_id4":"fourteen" }, "DC01AB491103":{ "field_id1":21, "field_id2":22, "field_id3"

Jackson2 Java to Json array ignore field names when creating array

只谈情不闲聊 提交于 2019-12-06 05:57:56
I'm trying to create a Java REST endpoint which returns a JSON data array to be consumed by JQuery FLOT charting plugin. At a minimum, the JSON data for FLOT needs to be an array of numbers i.e. [ [x1, y1], [x2, y2], ... ] Given I have a List of Point objects in Java i.e. List<Point> data = new ArrayList<>(); where Point is defined as public class Point { private final Integer x; private final Integer y; public Point(Integer x, Integer y) { this.x = x; this.y = y; } ... } What methods or Jackson2 annotations, if any, do I need to put on the Java objects to get the correct JSON format.

How do I invoke WriteJson recursively?

青春壹個敷衍的年華 提交于 2019-12-06 04:57:50
I use Json.Net. When I serialize a Department2 object and WriteJson() is invoked I want it to be recursively invoked with each of the Telephone2 objects like I do in ReadJson() . How do I do that? using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; public interface ISimpleDatabag { string Databag { get; set; } } [JsonConverter(typeof(JsonDataBagCreationConverter<Department2>))] public class Department2 { public Telephone2[] Phones { get; set; } } [JsonConverter(typeof(JsonDataBagCreationConverter<Telephone2>))] public class Telephone2 { public string Name { get; set; } public

JSON Serialization of a Django inherited model

巧了我就是萌 提交于 2019-12-06 04:04:46
问题 I have the following Django models class ConfigurationItem(models.Model): path = models.CharField('Path', max_length=1024) name = models.CharField('Name', max_length=1024, blank=True) description = models.CharField('Description', max_length=1024, blank=True) active = models.BooleanField('Active', default=True) is_leaf = models.BooleanField('Is a Leaf item', default=True) class Location(ConfigurationItem): address = models.CharField(max_length=1024, blank=True) phoneNumber = models.CharField

Remove concrete __type information in JSON Response using JsonSerializer

半城伤御伤魂 提交于 2019-12-05 15:03:48
问题 How do you force the __type information from rendering in the deserialized JSON response? I have no need to reserialize this data so I'd prefer to remove it. ServiceStack seems to add this to the dictionary properties of my model. This is using ServiceStack and ServiceStack.Text.JsonSerializer 回答1: By default the __type is only emitted when it's required for deserialization, e.g. your DTO contains an interface, abstract class or late-bound object type, etc. You can prevent it from ever being

MVC 3 - JSON serializer

这一生的挚爱 提交于 2019-12-05 01:41:52
问题 I have the following model, view and controller. Model public class Person { public string Name;// { get; set; } public string Occupation { get; set; } public int Salary { get; set; } public int[] NumArr { get; set; } } View <input type="button" id="Test" value="Test" /> @section Javascript{ <script type="text/javascript"> $(function () { $("#Test").click(function () { var data = { Name: "Michael Tom", Occupation: "Programmer", Salary: 8500, NumArr: [2,6,4,9] }; var url = "Home/GetJson"; $

error CS0234: The type or namespace name 'Script' does not exist in the namespace 'System.Web'

南楼画角 提交于 2019-12-04 22:13:43
I am trying to use JavaScriptSerializer in my application. I initially received Cannot find JavaScriptSerializer and I solved it by adding: using System.Web.Script.Serialization; But then the sub-keyword Script is underlined with a blue line: The type or namespace 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) So I added to the project a reference to: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.Extensions.dll That didn't help. I am still receiving the same blue underline with same error. The