我使用Spring Initializr生成了一个Spring Boot Web应用程序,在macOS Sierra中使用嵌入式Tomcat + Thymeleaf模板引擎,我必须解析Json对象
我有一个具有此属性的域对象:
@JsonProperty("activationTime")
private BigInteger activationTime;
但是当我解析对象时我犯了这个错误:
com.fasterxml.jackson.databind.JsonMappingException: Numeric value (1557587751202) out of range of int
at [Source: {"data":[{"id":"18AE62","name":"Device 0018AE62","type":"59147fd79e93a12e61499ffe","last":1515409036,"averageSignal":41.35125,"averageSnr":41.35125,"averageRssi":-109.87788,"state":0,"activationTime":1494515751202,"lat":0.0,"lng":0.0,"tokenType":"CONTRACT","contractId":"58d2956f3c87892877423fa3","tokenEnd":1557587751202,"preventRenewal":true,"automaticRenewal":false}],"paging":{}}; line: 1, column: 322]
at [Source: {"data":[{"id":"18AE62","name":"Device 0018AE62","type":"59147fd79e93a12e61499ffe","last":1515409036,"averageSignal":41.35125,"averageSnr":41.35125,"averageRssi":-109.87788,"state":0,"activationTime":1494515751202,"lat":0.0,"lng":0.0,"tokenType":"CONTRACT","contractId":"58d2956f3c87892877423fa3","tokenEnd":1557587751202,"preventRenewal":true,"automaticRenewal":false}],"paging":{}}; line: 1, column: 309] (through reference chain: com.ideefecloud.backend.sigfox.domain.backend.DevicesForAGivenDeviceType["data"]->java.util.ArrayList[0]->com.ideefecloud.backend.sigfox.domain.backend.Datum["tokenEnd"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:388)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:348)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1611)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:278)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:287)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:259)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:504)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:104)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3814)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2858)
at com.laberint.backend.service.SigfoxRestApiService.getDevicesForAGivenDeviceTypeDeviceType(SigfoxRestApiService.java:105)
at com.laberint.backend.service.SigfoxRestApiServiceTests.testGetAddressFromCoordinates(SigfoxRestApiServiceTests.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
Caused by: com.fasterxml.jackson.core.JsonParseException: Numeric value (1557587751202) out of range of int
at [Source: {"data":[{"id":"18AE62","name":"Device 0018AE62","type":"59147fd79e93a12e61499ffe","last":1515409036,"averageSignal":41.35125,"averageSnr":41.35125,"averageRssi":-109.87788,"state":0,"activationTime":1494515751202,"lat":0.0,"lng":0.0,"tokenType":"CONTRACT","contractId":"58d2956f3c87892877423fa3","tokenEnd":1557587751202,"preventRenewal":true,"automaticRenewal":false}],"paging":{}}; line: 1, column: 322]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558)
at com.fasterxml.jackson.core.base.ParserBase.convertNumberToInt(ParserBase.java:928)
at com.fasterxml.jackson.core.base.ParserBase._parseIntValue(ParserBase.java:866)
at com.fasterxml.jackson.core.base.ParserBase.getIntValue(ParserBase.java:694)
at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:299)
at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:279)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:504)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:104)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276)
... 41 more
答案 0 :(得分:2)
"tokenEnd":1557587751202
这是你的问题。 java中int
的最大值为2,147,483,647。将任何类别字段代表tokenEnd
更改为(例如)long
。