com.fasterxml.jackson.databind.JsonMappingException: Numeric value (1557587751202) out of range of int

北城以北 提交于 2021-02-04 14:08:02

问题


I've generated a Spring Boot web application using Spring Initializr, using embedded Tomcat + Thymeleaf template engine in a macOS Sierra., where I have to parse Json object

I have a domain object with this property:

@JsonProperty("activationTime")
private BigInteger activationTime;

But when I parse the object I this error:

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

回答1:


"tokenEnd":1557587751202

That's your problem. The maximum value for an int in java is 2,147,483,647. Change whatever class field represents tokenEnd to (for example) a long.



来源:https://stackoverflow.com/questions/49322922/com-fasterxml-jackson-databind-jsonmappingexception-numeric-value-155758775120

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!