草庐IT

collection_time

全部标签

java - 使用 Jackson 实现 Collection 的类的反序列化失败

我有以下JSON:{"item":[{"foo":1},{"foo":2}]}这基本上是一个包含项目集合的对象。所以我做了一个类来反序列化:publicclassItemList{@JsonProperty("item")Listitems;//Getters,setters&co.//...}到目前为止一切正常。现在,为了让我在其他地方的生活更轻松,我决定能够迭代ItemList对象并让它实现Collection接口(interface)会很好。所以基本上我的类(class)变成了:publicclassItemListimplementsCollection,Iterable{@J

java - Apache Http 客户端打印 "[read] I/O error: Read timed out""

我正在使用apachehttp客户端v4.5并将其用作REST客户端。在某些情况下,我发现一个错误“[读取]I/O错误:读取超时”,它来自httpclient框架,当它读取接收到的内容并将其显示为最后一条消息时。它似乎没有影响,但是我想知道是否有人知道它来自哪里以及如何解决它。根据以下线程(link),这似乎是“多线程”配置的问题。但是我只使用http客户端的默认配置,当我使用版本v4时,我不知道如何将“多线程”设置为false以查看它是否有任何区别。我也尝试设置超时,但没有帮助。有什么提示吗?日志:15:48:05.984[main]DEBUGorg.apache.http.wire

java - JPA 2.1 : Introducing Java 8 Date/Time API

我想在启用JPA的应用程序中添加对Java8日期/时间API(JSR-310)的支持。很明显JPA2.1doesnotsupporttheJava8Date/TimeAPI.作为解决方法,最常见的建议是使用AttributeConverter.在我现有的应用程序中,我将我的实体更改为对列映射字段使用LocalDate/LocalDateTime类型,并为java.util添加了旧版setter/getter.Date给他们。我创建了相应的AttributeConverter类。当使用Query.setParameter()和java.util.Date实例时,我的应用程序现在失败了(它

java - Stream collect with Generic 类型

我尝试在将json反序列化为pojo的方法中使用泛型,以便它可以返回任何对象类型。这是我的代码:privateBla(Listas,Listbs){this.as=as;this.bs=bs;}publicstaticBlafrom(JsonObjectjson){returnnewBla(Bla.load(json,As),Bla.load(json,Bs));}privatestaticListload(JsonObjectjsonObject,Stringparam){returnjsonObject.getJsonArray(param).stream().map(Bla::g

java - 什么可能导致套接字 ConnectException : Connection timed out?

我们有一个Webstart客户端,它使用java.net.HttpsURLConnection通过HTTPS发送序列化对象来与服务器通信。在我的本地机器和我们办公室的测试服务器上,一切都运行良好,但我遇到了一个非常非常奇怪的问题,它只发生在我们的生产和暂存服务器上(而且偶尔会出现)。我知道这些服务器与我们办公室的服务器之间的主要区别是它们位于其他地方,与它们的客户端-服务器通信速度相当慢,但在此之前的很长一段时间内,它在生产中也运行良好。无论如何,这是正在发生的事情:客户端在HttpURLConnection上设置读取超时等选项和Content-Type等属性后,调用getOutput

java - 为什么Stream <T> collect方法返回不同的键顺序?

我有以下代码:publicenumContinent{ASIA,EUROPE}publicclassCountry{privateStringname;privateContinentregion;publicCountry(Stringna,Continentreg){this.name=na;this.region=reg;}publicStringgetName(){returnname;}publicContinentgetRegion(){returnregion;}@OverridepublicStringtoString(){return"Country[name="+n

java - 如何将 util.Date 转换为 time.LocalDate 以正确处理 1893 年之前的日期

我google了一下,最常用的方法好像是date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();但是,对于1893-04-01之前的日期,此方法似乎会失败以下测试在我的机器上失败,结果为1893-03-31而不是1893-04-01:@TestpublicvoidtestBeforeApril1893()throwsParseException{Datedate=newSimpleDateFormat("yyyy-MM-dd").parse("1893-04-01");System.out.println(date);

java - JPA 标准 API : How to select property in nested collection

我有一个类Customer和CustomerDependant实体。Customer与其家属有多对多的双向关系。我需要查找按姓名和相关姓名过滤的客户。它在JPQL中做了类似这样的事情:selectcjoinfetchc.dependantsdfromCustomercwherec.namelike'foo'andd.namelike'foo'我如何使用JPA标准查询做同样的事情? 最佳答案 摘自JPA规范第6.5.4节CriteriaQueryq=cb.createQuery(Department.class);Rootd=q.fr

java.time : DateTimeParseException for date "20150901023302166"

这个问题在这里已经有了答案:Isjava.timefailingtoparsefraction-of-second?(3个答案)关闭7年前。LocalDateTime.parse("20150901023302166",DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"))给出错误:java.time.format.DateTimeParseException:Text'20150901023302166'couldnotbeparsedatindex0

java - 为什么 NodeList 不扩展 Collection 或 Iterable?

也许这不完全是一个编程问题。但是……为什么是org.w3c.dom.NodeList不是java.lang.Iterable的扩展名界面?这对我来说听起来很反直觉。特别是因为文档说:TheNodeListinterfaceprovidestheabstractionofanorderedcollectionofnodes,withoutdefiningorconstraininghowthiscollectionisimplemented.NodeListobjectsintheDOMarelive.TheitemsintheNodeListareaccessibleviaaninte