我正在尝试使用注释来控制序列化格式.但似乎没有任何方法可以从TypeAdapter或TypeAdapterFactory中访问字段注释.
这是我想要实现的一个例子.
import org.joda.time.DateTime;
public class Movie {
String title;
@DateTimeFormat("E, M d yyyy")
DateTime releaseDate;
// other fields ...
}
public class LogEvent {
String message;
@DateTimeFormat("yyyyMMdd'T'HHmmss.SSSZ")
DateTime timestamp;
}
Run Code Online (Sandbox Code Playgroud)
对于Movie对象,我想将日期序列化为"2013年8月24日星期六",但是对于LogEvent,"20130824T103025.123Z".
我试图这样做而不必为每个类编写单独的TypeAdapterFactory(想象一下,如果我们有100个不同的类,其中DateTime字段需要不同的格式)
TIA!