当我将其放入avro模式时:
{ "name": "the_id", "type": "int" },
Run Code Online (Sandbox Code Playgroud)
然后我:
mvn generate-sources
Run Code Online (Sandbox Code Playgroud)
生成一个包含以下内容的类文件:
private int the_id;
/**
* All-args constructor.
*/
public TheObject(java.lang.Integer the_id, ...
public java.lang.Integer getTheId() {
return the_id;
}
Run Code Online (Sandbox Code Playgroud)
“ the_id”被声明为int,然后在构造函数和getter(和setter中装箱成Integer,尽管我没有在代码示例中包括它)。
应用“自动装箱不利于性能”的原则,我想阻止这种情况的发生。我检查了文档并浏览了论坛,但没有发现任何有用的信息:(此Avro邮件归档文章建议在现代JVM中自动装箱是“免费的”,但Oracle的这篇文章不同意)。同时,此 Avro邮件存档中的帖子未得到答复。
有人知道阻止Avro自动装箱的方法吗?
我试图解析datetime字符串并创建Joda DateTime对象。
我的数据来自存储日期时间字符串而不指定时区/偏移量的旧数据库。尽管没有存储日期时间字符串的时区/偏移量,但这是旧系统的业务规则,即所有日期时间都存储在东部时间中。不幸的是,我无权更新旧版数据库存储日期时间字符串的方式。
因此,我使用JODA的“美国/东部”时区解析日期时间字符串。
当dateTime字符串落在启用夏令时时“消失”的小时之内,则此方法将引发llegalInstance异常。
我创建了以下示例代码来演示此行为并展示我建议的解决方法。
public class FooBar {
public static final DateTimeZone EST = DateTimeZone.forID("EST");
public static final DateTimeZone EASTERN = DateTimeZone.forID("US/Eastern");
public static final DateTimeFormatter EST_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(EST);
public static final DateTimeFormatter EASTERN_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(EASTERN);
public static void main(String[] args) {
final String[] listOfDateTimeStrings = {"2014-03-09 02:00:00.000", "2014-03-08 02:00:00.000"};
System.out.println(" *********** 1st attempt *********** ");
for (String dateTimeString: listOfDateTimeStrings){
try{
final DateTime dateTime = DateTime.parse(dateTimeString, EASTERN_FORMATTER);
System.out.println(dateTime);
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
System.out.println(" *********** …Run Code Online (Sandbox Code Playgroud)