当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Efficient way to custom serialize a joda LocalDate

问题描述:

I need to write a custom serializer for a joda LocalDate. Serializer should be as fast as possible, and create an output which is as small as possible.

I can send basic Java primitives and objects over the wire, e.g. long, boolean, int, String, etc, but not objects of any Joda types.

I've noticied an internal "iLocalMillis" field which is not publicly accessable. Also not sure how to serialize the Chronology component...

Any help would be appreciated.

Cheers

网友答案:

This answer is sufficient and simple if ISOChronology is enough for you:

  1. Write the attributes getYear(), getMonthOfYear() and getDayOfMonth() out.
  2. Read the three mentioned integer attributes and use this constructor of LocalDate.

In the case you need to serialize the Chronology then you are a little bit out of luck and have to study the serialization form of each concrete chronology you need as published in JavaDoc. One example is the serialization form of GJChronology.

分享给朋友:
您可能感兴趣的文章:
随机阅读: