Created
January 6, 2018 00:32
-
-
Save greenlaw110/f9549423f3026a428858f81ac7b1449f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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