serialization

jackson serialization of nested objects

佐手、 提交于 2021-01-27 04:37:51
问题 I have problem with jackson serialization of object by its interface. I have class class Point implements PointView { private String id; private String name; public Point() { } public Point(String id, String name) { this.id = id; this.name = name; } @Override public String getId() { return id; } public String getName() { return name; } } which implements interface PointView { String getId(); } and have class class Map implements MapView { private String id; private String name; private Point

encoding/json unmarshal missing a field

醉酒当歌 提交于 2021-01-26 19:15:11
问题 The following code unmarshal's the "Id", but not the "Hostname". Why? I've been staring at it for long enough now that if it's a typo I know I'll never spot it. Help please. (http://play.golang.org/p/DIRa2MvvAV) package main import ( "encoding/json" "fmt" ) type jsonStatus struct { Hostname string `json:host` Id string `json:id` } func main() { msg := []byte(`{"host":"Host","id":"Identifier"}`) status := new(jsonStatus) err := json.Unmarshal(msg, &status) if err != nil { fmt.Println(

encoding/json unmarshal missing a field

ぃ、小莉子 提交于 2021-01-26 19:15:08
问题 The following code unmarshal's the "Id", but not the "Hostname". Why? I've been staring at it for long enough now that if it's a typo I know I'll never spot it. Help please. (http://play.golang.org/p/DIRa2MvvAV) package main import ( "encoding/json" "fmt" ) type jsonStatus struct { Hostname string `json:host` Id string `json:id` } func main() { msg := []byte(`{"host":"Host","id":"Identifier"}`) status := new(jsonStatus) err := json.Unmarshal(msg, &status) if err != nil { fmt.Println(

How to serialize boolean to JSON as strings using Jackson

拜拜、爱过 提交于 2021-01-26 07:59:51
问题 We have developed a REST service using Jersey JAX-RS and Jackson (version 2.1.5) for JSON serialization. As the application is supposed to be a drop-in replacement for the older legacy service acting as a backend to an existing mobile app, we need to do some tweaking to the way Jackson serializes boolean values. Existing mobile app expects boolean values to be expressed as strings of "true" and "false" like this: {"Foo":"true","Bar":"false"} So I have searched for a way to influence the

How can we write a generic function for checking Serde serialization and deserialization?

我与影子孤独终老i 提交于 2021-01-26 03:23:43
问题 In a project where custom Serde (1.0) serialization and deserialization methods are involved, I have relied on this test routine to check whether serializing an object and back would yield an equivalent object. // let o: T = ...; let buf: Vec<u8> = to_vec(&o).unwrap(); let o2: T = from_slice(&buf).unwrap(); assert_eq!(o, o2); Doing this inline works pretty well. My next step towards reusability was to make a function check_serde for this purpose. pub fn check_serde<T>(o: T) where T: Debug +

How can we write a generic function for checking Serde serialization and deserialization?

谁说胖子不能爱 提交于 2021-01-26 03:22:57
问题 In a project where custom Serde (1.0) serialization and deserialization methods are involved, I have relied on this test routine to check whether serializing an object and back would yield an equivalent object. // let o: T = ...; let buf: Vec<u8> = to_vec(&o).unwrap(); let o2: T = from_slice(&buf).unwrap(); assert_eq!(o, o2); Doing this inline works pretty well. My next step towards reusability was to make a function check_serde for this purpose. pub fn check_serde<T>(o: T) where T: Debug +

Conditional JSON serialization using C#

半腔热情 提交于 2021-01-24 08:48:26
问题 I have a class that I serialize to JSON in C# and post to a RESTful web service. I have a requirment that if one field is filled out another field not be present. The service errors if both fields are serialized into the JSON object. My class looks like this: [DataContract(Name = "test-object")] public class TestObject { [DataMember(Name = "name")] public string Name { get; set; } // If string-value is not null or whitespace do not serialize bool-value [DataMember(Name = "bool-value")] public

Conditional JSON serialization using C#

只愿长相守 提交于 2021-01-24 08:48:02
问题 I have a class that I serialize to JSON in C# and post to a RESTful web service. I have a requirment that if one field is filled out another field not be present. The service errors if both fields are serialized into the JSON object. My class looks like this: [DataContract(Name = "test-object")] public class TestObject { [DataMember(Name = "name")] public string Name { get; set; } // If string-value is not null or whitespace do not serialize bool-value [DataMember(Name = "bool-value")] public

Conditional JSON serialization using C#

大城市里の小女人 提交于 2021-01-24 08:46:06
问题 I have a class that I serialize to JSON in C# and post to a RESTful web service. I have a requirment that if one field is filled out another field not be present. The service errors if both fields are serialized into the JSON object. My class looks like this: [DataContract(Name = "test-object")] public class TestObject { [DataMember(Name = "name")] public string Name { get; set; } // If string-value is not null or whitespace do not serialize bool-value [DataMember(Name = "bool-value")] public

There is a clean way to return string as json in a Spring Web API?

冷暖自知 提交于 2021-01-24 08:13:00
问题 For example, I had to implement as below: @RequestMapping(value = "/get-string", method = {RequestMethod.GET}) public @ResponseBody String getString() { return "Hello World!"; } When the action is called by Ajax in a JS file, the response received is: HelloWorld . So, if the Ajax request is configured to only receive json encoded responses, I receive the standard deconding error. To solve this problem in server-side, I need to receive "HelloWorld" . My question is: There is a clean way I can