Skip to content

Instantly share code, notes, and snippets.

@greenlaw110
Created January 6, 2018 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenlaw110/f9549423f3026a428858f81ac7b1449f to your computer and use it in GitHub Desktop.
Save greenlaw110/f9549423f3026a428858f81ac7b1449f to your computer and use it in GitHub Desktop.
public class FastJsonIssue {
public static class Record {
@JSONField(format = "yyyy-MMM-dd")
public Date date1 = new Date();
@JSONField(format = "yyyyMMdd")
public Date date2 = date1;
@JSONField(format = "yyyy_MM_dd hh:mm")
public DateTime dateTime = DateTime.now();
}
public static class JodaDateTimeSerializer implements ObjectSerializer {
@Override
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
SerializeWriter out = serializer.getWriter();
if (object == null) {
out.writeNull();
} else {
Class cls = object.getClass();
if (cls == DateTime.class) {
out.writeString(object.toString());
} else {
out.writeString(object.toString());
}
}
}
}
public static void main(String[] args) {
SerializeConfig.getGlobalInstance().put(DateTime.class, new JodaDateTimeSerializer());
System.out.println(JSON.toJSONString(new Record()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment