JodaDateTime
メンバーを持つオブジェクトをシリアル化するためにjacksonを使用して作業を開始しようとしています。
次のシリアライザーを作成しました。
public class DateTimeSerializer extends JsonSerializer<DateTime> {
private static DateTimeFormatter formatter =
DateTimeFormat.forPattern("dd-MM-yyyy HH:mm:ss, SSS [z]");
@Override
public void serialize(DateTime value, JsonGenerator gen,
SerializerProvider arg2) throws IOException,
JsonProcessingException {
gen.writeString(formatter.print(value));
}
@Override
public Class<DateTime> handledType() {
return DateTime.class;
}
}
DateTime
そして、次のようにメンバーを持つクラスをシリアル化しようとしています。
Version version = new Version(1, 0, 0, "SNAPSHOT");
SimpleModule module = new SimpleModule("ZORRO", version);
module = module.addSerializer(new DateTimeSerializer());
// and so on...
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
mapper.writeValue(new File("C:\\tmp\\window1.json"), window1);
次の例外が発生します(何が間違っているのか理解できません):
java.lang.TypeNotPresentException: Type org.joda.convert.ToString not present
at com.ibm.oti.reflect.AnnotationHelper.getAnnotation(AnnotationHelper.java:38)
at com.ibm.oti.reflect.AnnotationHelper.getDeclaredAnnotations(AnnotationHelper.java:50)
at com.ibm.oti.reflect.Method.getDeclaredAnnotations(Method.java:31)
at java.lang.reflect.Method.getDeclaredAnnotations(Method.java:687)
at org.codehaus.jackson.map.introspect.AnnotatedClass._addMixUnders(AnnotatedClass.java:973)
at org.codehaus.jackson.map.introspect.AnnotatedClass._addMemberMethods(AnnotatedClass.java:637)
at org.codehaus.jackson.map.introspect.AnnotatedClass.resolveMemberMethods(AnnotatedClass.java:413)
at org.codehaus.jackson.map.introspect.BasicClassIntrospector.classWithCreators(BasicClassIntrospector.java:185)
at org.codehaus.jackson.map.introspect.BasicClassIntrospector.collectProperties(BasicClassIntrospector.java:157)
at org.codehaus.jackson.map.introspect.BasicClassIntrospector.forSerialization(BasicClassIntrospector.java:96)
at org.codehaus.jackson.map.introspect.BasicClassIntrospector.forSerialization(BasicClassIntrospector.java:16)
at org.codehaus.jackson.map.SerializationConfig.introspect(SerializationConfig.java:973)
at org.codehaus.jackson.map.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:251)
at org.codehaus.jackson.map.ser.StdSerializerProvider._createUntypedSerializer(StdSerializerProvider.java:782)
at org.codehaus.jackson.map.ser.StdSerializerProvider._createAndCacheUntypedSerializer(StdSerializerProvider.java:758)
at org.codehaus.jackson.map.ser.StdSerializerProvider.findValueSerializer(StdSerializerProvider.java:380)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.resolve(BeanSerializerBase.java:307)
at org.codehaus.jackson.map.ser.impl.SerializerCache.addAndResolveNonTypedSerializer(SerializerCache.java:159)
at org.codehaus.jackson.map.ser.StdSerializerProvider._createAndCacheUntypedSerializer(StdSerializerProvider.java:744)
at org.codehaus.jackson.map.ser.StdSerializerProvider.findValueSerializer(StdSerializerProvider.java:344)
at org.codehaus.jackson.map.ser.StdSerializerProvider.findTypedValueSerializer(StdSerializerProvider.java:420)
at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:601)
at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:256)
at org.codehaus.jackson.map.ObjectMapper._configAndWriteValue(ObjectMapper.java:2575)
at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:2048)