serialization

Easy way to serialize/deserialize public enums?

早过忘川 提交于 2019-12-24 00:34:13
问题 I am having some trouble trying to serialize/deserialize some enum in Java. Here is my enum class: FrequencyType.java: @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public enum FrequencyType { NONE, HOURLY, DAILY, WEEKLY, MONTHLY; } Controller.java @RequestMapping(method = RequestMethod.POST) public Object createFrequency(@RequestBody FrequencyType frequencyType) throws Exception { ... frequencyManager.createFrequency(frequencyType); ... } I am trying to use the

Update objects written to a text files in java

左心房为你撑大大i 提交于 2019-12-24 00:33:18
问题 Writing Java objects or a List into a text file is ok. But I want to know how I can update or rewrite a object which was written previously without writing objects again. For example, let s assume there is a java.util.List has a set of Objects. and then that list is written to a text file. Then later that file will be read again and get all objects from list and then change one object's value at run time by a java application. Then I don't need to write entire list back to the text file.

Array subclasses cannot be deserialized, Error #1034

懵懂的女人 提交于 2019-12-23 23:48:07
问题 I've just found a strange error when deserializing from a ByteArray , where Vector s cannot contain types that extend Array : there is a TypeError when they are deserialized. TypeError: Error #1034: Type Coercion failed: cannot convert []@4b8c42e1 to com.myapp.ArraySubclass. at flash.utils::ByteArray/readObject() at com.myapp::MyApplication()[/Users/aaaidan/MyApp/com/myapp/MyApplication.as:99] Here's how: public class Application extends Sprite { public function Application() { // register

Performance cost of serialization and compress a Object in Java

纵饮孤独 提交于 2019-12-23 23:08:55
问题 The application keeps receiving objects named Report and put the objects into Disruptor for three different consumers. With the help of Eclipse Memory Analysis, the Retained Heap Size of each Report object is 20KB on average. The application starts with -Xmx2048 , indicating the heap size of the application is 2GB. However, the number of the objects is around 100,000 at a time, which means that the total size of all the object is roughly 2GB. The requirement is that all 100,000 objects should

DRF serializer change field to read_only for some model instances

自闭症网瘾萝莉.ら 提交于 2019-12-23 22:07:32
问题 I have this model: class Task(MPTTModel, TimeStampedModel, StartFinishModel): name = models.CharField(max_length=256) parent = TreeForeignKey('self', on_delete=models.CASCADE, related_name='children') start_date = models.DateField() finish_date = models.DateField() @property def is_stage(self): if self.get_children(): return True return False And serializer: class TaskBaseSerializer(StartFinishSerializer, TimeStampedSerializer): class Meta: model = Task fields = ('id', 'name', 'parent',

Change Object just before JSON serialization

久未见 提交于 2019-12-23 22:07:18
问题 I want to change an object just before JSON Serialization. To do it, I've created an interface, with change method, and any class that implements this interface will "try" to change itself. ( yes, probably doing it like this is not optimal, but for example sake will do ) @JsonSerialize(using = ChangesValuesSerializer.class) public interface ChangesValues { void changeValues(); } Now, is ChangesValuesSerializer class I'm implementing serialize method. And want to know, how can I say Jackson,

Java ClassNotFoundException when reading object from a stream

雨燕双飞 提交于 2019-12-23 22:07:06
问题 I am getting a ClassNotFoundException when reading an Object from an ObjectInputStream. The object that is being sent is subclassing "WorkUnit" which the reading code has a reference to. It would seem that the receiving end is complaining because it doesn't know about the specific implementation. Why would it care about that when I'm only referencing the object's superclass: "WorkUnit" on the side that is receiving? Code to read from Stream: private Object readObject() { Object object = null;

DataContract SerializationException when using list of predicates

二次信任 提交于 2019-12-23 21:16:13
问题 I'm writing a generic filter class that will be primarily used to filter persons from a population. I'm trying to serialize the filter class, but at runtime I get an SerializationException: System.Runtime.Serialization.SerializationException : Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name 'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System' is not expected. Consider using a DataContractResolver or add any types not known

JSON deserialization throwing exception - Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

≡放荡痞女 提交于 2019-12-23 20:58:07
问题 The below is my JSON response, Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.PushbackInputStream@bce1d9; line: 1, column: 556] (through reference chain: com.totalHours["data"]->com.totalHours["hourly_totals"]) "totalHours": { "hourly_totals": { "2013112101": { "distance": 1324, "calories": 90.0120018125, "steps": 1603, "active_time": 793, "inactive_time": 220, "longest_active

How do I serialize Moose objects to XML?

不打扰是莪最后的温柔 提交于 2019-12-23 20:51:39
问题 I have a bunch of legacy modules I want to convert to being Moose-based. The modules currently have "toXML" methods, which are hand-coded using XML::LibXML. Is there a module or technique for serializing Moose objects to XML? I have looked at MooseX::Storage, but that handles JSON, YAML, and Storage, not XML. A google search for Moose and XML yields lots of references to XML::Rabbit, which seems to be good for parsing XML into Moose classes, but there's not a lot out there for taking Moose