serialization

c#: how to hide a field which is used only for XML serialization retrocompatibility?

二次信任 提交于 2021-02-05 08:55:03
问题 The field is used only during the serialization / deserialization process but I would like to immediately encapsulate it and hide from the class. Is it possible? 回答1: Basically, no. XmlSerializer only works with public members, so you can't make it internal or private . You can add some attributes to make it less glaring especially in UIs that data-bind: [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public int Foo {get; set; } but that only masks it. You could also look at

Java unable to serialize a objects which contain TreeMaps with Comparators

让人想犯罪 __ 提交于 2021-02-05 06:48:06
问题 I have as an assignment (for the OOP course from Uni) a pretty large project: a school register, where students can see their grades, teachers can add grades and so on. The "base" class is a singleton which contains all the classes (Java) used, such as an array of users, classes (as in school classes) and a TreeMap that associates classess and teachers to courses. I want to serialize this base class (Central), in order to save the modified data. The problem is that I get this exception java

Deserializing map key with Gson expects an object

∥☆過路亽.° 提交于 2021-02-05 05:32:29
问题 I get the error: Exception in thread "main" com.google.gson.JsonParseException: Expecting object found: "com.shagie.app.SimpleMap$Data@24a37368" when trying to deseralize a Map that uses non-trivial keys: package com.shagie.app; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.util.HashMap; public class SimpleMap { public static void main(String[] args) { Wrapper w = new Wrapper(); w.m.put(new Data("f", 1), new Data("foo", 3)); w.m.put(new Data("b", 2), new Data(

WCF Service . Setting response type to XML/JSON using the Accept HTTP Header?

﹥>﹥吖頭↗ 提交于 2021-02-04 21:07:16
问题 I want my WCF service to accept and respond to requests in JSON or XML. I thought that WCF was supposed to automatically interpret the response type based on the Accept header that the client specifies. However in my client request I specify the accept header to be application/json but I receive an XML response. This is my service definition: [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/GetChecks", BodyStyle = WebMessageBodyStyle.Bare)] Check[] GetChecks(MyCustomObj Object)

WCF Service . Setting response type to XML/JSON using the Accept HTTP Header?

非 Y 不嫁゛ 提交于 2021-02-04 21:06:01
问题 I want my WCF service to accept and respond to requests in JSON or XML. I thought that WCF was supposed to automatically interpret the response type based on the Accept header that the client specifies. However in my client request I specify the accept header to be application/json but I receive an XML response. This is my service definition: [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/GetChecks", BodyStyle = WebMessageBodyStyle.Bare)] Check[] GetChecks(MyCustomObj Object)

'Circular reference has been detected' error when serializing many-to-many-associated objects

岁酱吖の 提交于 2021-02-04 17:59:10
问题 Since upgrading to Symfony 2.7, I seem to keep getting 'circular reference has been detected' errors when attempting to serialize an array of contacts associated with a given group. They're setup in a many-to-many association (one group has many contacts; one contact has many group-associations). Now, I followed the guide for using serialization groups as per the 2.7 upgrade post, but still seem to get the error. My controller code for this is currently as follows: $group = $this->getDoctrine

How do I configure Jackson Serialization on LocalDateTime and LocalDate for Java?

非 Y 不嫁゛ 提交于 2021-02-04 08:14:25
问题 I know that there are many posts on Stackoverflow regarding this topic and I'm sure I've read just about all of them, but I am still struggling to get this working and would appreciate any guidance. This is the Spring Parent and Jackson Dependencies I am using: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <!-- Jackson --> <dependency> <groupId>com.fasterxml.jackson.module</groupId>

How to deserialise enumeration with string representation?

落爺英雄遲暮 提交于 2021-02-04 07:31:30
问题 I would like to create a class, which has an enumeration as an attribute. This enumeration should have a string representation that shows up as human-readable value when dumping the instance of the class that uses the enum attribute as a JSON string. In the minimal working example below, I created three enumerations in three different ways. After the deserialization, each attribute shows us that it comes from an enumeration except the enumeration with a string representation. It is just a

How to deserialise enumeration with string representation?

我的未来我决定 提交于 2021-02-04 07:30:25
问题 I would like to create a class, which has an enumeration as an attribute. This enumeration should have a string representation that shows up as human-readable value when dumping the instance of the class that uses the enum attribute as a JSON string. In the minimal working example below, I created three enumerations in three different ways. After the deserialization, each attribute shows us that it comes from an enumeration except the enumeration with a string representation. It is just a

How to ignore field totally by its value when serializing with Jackson with annotation on that field?

半城伤御伤魂 提交于 2021-01-29 20:32:31
问题 Almost the same question but the accepted answer does not fit the general need. Having Simple class and custom serializer like: Example class @Getter @Setter public class ExampleClass { @JsonInclude(JsonInclude.Include.NON_NULL) @JsonSerialize(using = StringSerializer.class) private String stringNull; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonSerialize(using = StringSerializer.class) private String stringOk = "ok"; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonSerialize(converter =