- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 Jersey REST Web 服务,它接受 POSTed XML 字符串。我为 XML 的每个元素都有实体,以便将它们拆分为对象。当我传递日期参数时,例如InspectionDate="12/02/2012"我收到以下错误。
SEVERE: Servlet.service() for servlet [Jersey REST Service] in context with path [] threw exception
java.lang.IllegalArgumentException: 12/02/2012
at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parseAndSetYear(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(Unknown Source)
at com.sun.xml.bind.DatatypeConverterImpl._parseDateTime(DatatypeConverterImpl.java:400)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$5.parse(RuntimeBuiltinLeafInfoImpl.java:271)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$5.parse(RuntimeBuiltinLeafInfoImpl.java:273)
at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:241)
at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:201)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:481)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:124)
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:97)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:393)
at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:139)
at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:43)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:126)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:173)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:163)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:654)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:612)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:603)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:309)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:425)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:590)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
这是我的 XML 字符串:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<user userName="Test.Test" userID="43">
<client>
<site>
<building>
<location>
<asset assetID="293">
<inspection assetID="293" inspectionDate="12/02/2012" inspectionRef="inspection_ref_89158">
<comments>Test</comments>
<assessedBy>Natasha Allsopp</assessedBy>
<assessed>false</assessed>
<notAssessedReason>Access Hatch Padlocked<notAssessedReason>
<acceptable>true</acceptable>
<remedialActionRequired>false</remedialActionRequired>
<remedialActionID>0</remedialActionID>
<flowTemperature>0.0</flowTemperature>
<returnTemperature>0.0</returnTemperature>
<temperature1MinHot>0.0</temperature1MinHot>
<temperature2MinCold>0.0</temperature2MinCold>
<showerHeadsPresent>4</showerHeadsPresent>
<showerHeadsCleaned>0</showerHeadsCleaned>
<showersNotCleanedReason></showersNotCleanedReason>
<storedWaterTemperature>0.0</storedWaterTemperature>
<incomingMainsTemperature>0.0</incomingMainsTemperature>
<anyLeaks>false</anyLeaks>
<sludgePresent>None</sludgePresent>
<corrosionPresent>None</corrosionPresent>
<flotsamPresent>None</flotsamPresent>
<turnoverCheck>Good</turnoverCheck>
<conditionofTank>Good</conditionofTank>
<goodFittingLidPresent>false</goodFittingLidPresent>
<lidVented>false</lidVented>
<ventScreened>false</ventScreened>
<overflowPresent>false</overflowPresent>
<insectScreen>false</insectScreen>
</inspection>
</asset>
</location>
</building>
</site>
</client>
</user>
这是我的实体类的片段:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"inspectionDate"})
public class Inspection {
@XmlAttribute
protected Date inspectionDate;
@XmlAttribute
protected String inspectionRef;
public Date getInspectionDate() {
return inspectionDate;
}
public void setInspectionDate(Date inspectionDate) {
this.inspectionDate = inspectionDate;
}
}
如果我使用以下 XMLJavaAdapter:
public class DateAdapter extends XmlAdapter<String, Date> {
private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
@Override
public String marshal(Date v) throws Exception {
return dateFormat.format(v);
}
@Override
public Date unmarshal(String v) throws Exception {
return dateFormat.parse(v);
}
}
我收到以下错误:
SEVERE: Servlet.service() for servlet [Jersey REST Service] in context with path [] threw exception [com.sun.jersey.api.container.MappableContainerException: java.io.IOException: Error unmarshalling JAXB object of type "class dao.jpa.User".] with root cause
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
There are two properties named "inspectionDate"
this problem is related to the following location:
at public java.util.Date dao.jpa.Inspection.getInspectionDate()
at dao.jpa.Inspection
at protected dao.jpa.Inspection dao.jpa.Asset.inspection
at dao.jpa.Asset
at protected dao.jpa.Asset dao.jpa.Location.asset
at dao.jpa.Location
at protected dao.jpa.Location dao.jpa.Building.location
at dao.jpa.Building
at protected dao.jpa.Building dao.jpa.Site.building
at dao.jpa.Site
at protected dao.jpa.Site dao.jpa.Client.site
at dao.jpa.Client
at protected dao.jpa.Client dao.jpa.User.client
at dao.jpa.User
this problem is related to the following location:
at protected java.util.Date dao.jpa.Inspection.inspectionDate
at dao.jpa.Inspection
at protected dao.jpa.Inspection dao.jpa.Asset.inspection
at dao.jpa.Asset
at protected dao.jpa.Asset dao.jpa.Location.asset
at dao.jpa.Location
at protected dao.jpa.Location dao.jpa.Building.location
at dao.jpa.Building
at protected dao.jpa.Building dao.jpa.Site.building
at dao.jpa.Site
at protected dao.jpa.Site dao.jpa.Client.site
at dao.jpa.Client
at protected dao.jpa.Client dao.jpa.User.client
at dao.jpa.User
Class has two properties of the same name "inspectionDate"
this problem is related to the following location:
at public java.util.Date dao.jpa.Inspection.getInspectionDate()
at dao.jpa.Inspection
at protected dao.jpa.Inspection dao.jpa.Asset.inspection
at dao.jpa.Asset
at protected dao.jpa.Asset dao.jpa.Location.asset
at dao.jpa.Location
at protected dao.jpa.Location dao.jpa.Building.location
at dao.jpa.Building
at protected dao.jpa.Building dao.jpa.Site.building
at dao.jpa.Site
at protected dao.jpa.Site dao.jpa.Client.site
at dao.jpa.Client
at protected dao.jpa.Client dao.jpa.User.client
at dao.jpa.User
this problem is related to the following location:
at protected java.util.Date dao.jpa.Inspection.inspectionDate
at dao.jpa.Inspection
at protected dao.jpa.Inspection dao.jpa.Asset.inspection
at dao.jpa.Asset
at protected dao.jpa.Asset dao.jpa.Location.asset
at dao.jpa.Location
at protected dao.jpa.Location dao.jpa.Building.location
at dao.jpa.Building
at protected dao.jpa.Building dao.jpa.Site.building
at dao.jpa.Site
at protected dao.jpa.Site dao.jpa.Client.site
at dao.jpa.Client
at protected dao.jpa.Client dao.jpa.User.client
at dao.jpa.User
at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:302)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getStoredJAXBContext(AbstractJAXBProvider.java:199)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getJAXBContext(AbstractJAXBProvider.java:177)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getUnmarshaller(AbstractJAXBProvider.java:131)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getUnmarshaller(AbstractJAXBProvider.java:104)
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:97)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:393)
at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:139)
at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:43)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:126)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:173)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:163)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:654)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:612)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:603)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:309)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:425)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:590)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
如果有人有任何想法,请告诉我。
最佳答案
我的猜测是,您正在获取两个属性...
,异常(exception)的是,在您的真实类中,您在 get 方法上添加了 @XmlJavaTypeAdapter(DateAdapter.class)
注释,而不是在具有 @XmlAttribute
注释的字段。
关于java - Jersey REST 日期 @XmlAttribute 导致非法参数异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22297928/
我正在将我的 xml 反序列化为 C# 类。
从 MusicBrainz REST 服务,我得到以下 xml: ... 使用 WCF 和 XmlSerializationFormat,我能够获取类型和 ID 属性...但是如何获取“e
我想在派生类中编码 XMLAttribute,但我遇到了一些问题。 我有 2 个派生类和 1 个父类(super class),如下所示: public class Dog extends Anima
我在以下类(class)中收到以下错误: 无法序列化 DataObjects.Ingredient 类型的成员“成分”。 XmlAttribute/XmlText 不能用于编码复杂类型。 关于为什么的
在我的网络服务上,我将变量定义为@XmlAttribute: @XmlAttribute protected String domain; 但是当我通过 SoapUi 进行查询时,它显示为 XML 元
我在使用 XmlSerializer 生成以下 XML 结构时遇到问题: This is root. Otha. This Is Circ
例如我有一个简单的类 class SomeCfg { [XmlAttribute("ArchivePath")] public string ArchivePath { get; se
我正在尝试使用 javax.xml.bind.annotation 将属性添加到简单类型(在本例中为 String) 所以我想要这个 data 如果 stuff 是 'myObj' 中的字符串,这可能
我想将类 Ticket 序列化为 xml。由于我的自定义字段类,我收到错误:“XmlAttribute/XmlText 不能用于编码复杂类型”。 自定义字段的 xml 应该是这样的(属性数组是 nes
我有很多属性要使用 XmlSerializer 进行序列化。我需要用 [XmlAttribute] 标记每个(简单的)属性,以使输出更短一些。我想知道是否有更简单的方法来做到这一点。有没有办法让它成为
我正在寻找谁来自定义属性的序列化。我以为这会很简单,但我无法按照我想要的方式实现我想做的事情。 所以这是一个简单的例子: 类定义: Class MyClass { [XmlAttribute(
我有一个 XML 文件,它需要一个元素中的 3 个属性。如何按照我的意愿制作街道, zip 和城市属性的顺序? @XmlType(name="Street) @XmlRootElement(nam
我正在制作 SOAP Web 服务以及何时使用 @XmlAttribute(name = "asd:resource") private String asdResource; 我无法在 SoapUI
这个问题已经有答案了: How to change a field name in JSON using Jackson (4 个回答) 已关闭 7 年前。 这似乎是一个奇怪的问题,但这是由于旧版前端
我有一个 XML 文件,它需要在一个元素中有 3 个属性。如何使街道、邮政编码和城市属性的顺序符合我的要求? @XmlType(name="Street) @XmlRootElement(name
有一个带有这样的字段的光环类: private String description; // a lot of text private long price; private int count
我希望能够做这样的事情: //buildArgs XmlNode buildArgs = doc.CreateElement("buildArgs"); XmlAttribute buildAr
我是 JAXB 的新手,在从 XML 到 Java 类实例的转换方面遇到了麻烦。 我有以下 XML: client Greeting 1000 Your Conne
假设我有以下代码,并希望序列化为代码下方的 XML: class Human { [XmlElement("OwnedObjects")] public List ownedObjec
这是我的属性(property): /// /// The Business Unit /// [XmlAttribute("ows_Business_x0020_
我是一名优秀的程序员,十分优秀!