fastjson FALSE字符串用JSON.parseObject()转Object时报错

atmip9wb  于 2021-11-27  发布在  Java
关注(0)|答案(5)|浏览(745)

1、JSON.parseObject(value, type); type为Boolean对象的Type、value为FALSE字符串,使用此方法会报异常
2、JSON.parseObject(value, type); type为Boolean对象的Type、value为false字符串,使用此方法不会报错
3、JSON.parseObject(value, type); type为Boolean对象的Type、value为TRUE字符串,使用此方法不会报错
4、JSON.parseObject(value, type); type为Boolean对象的Type、value为true字符串,使用此方法会报错
也就是说当value为大写的FALSE字符串时此方法会报错,fastJson版本为1.2.28

xzabzqsa

xzabzqsa2#

用了1.2.36也是会报错的,但是报错不一样了
com.alibaba.fastjson.JSONException: parseBoolean error, field : null
at com.alibaba.fastjson.serializer.BooleanCodec.deserialze(BooleanCodec.java:84)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:623)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:361)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:329)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:292)
at com.zhubajie.framework.test.util.common.StringUtils.json2Bean(StringUtils.java:110)
at com.zhubajie.framework.test.util.common.StringUtils.transferMap2Bean(StringUtils.java:243)
at com.zhubajie.framework.test.util.common.CommonInitUtils.commonInit(CommonInitUtils.java:79)
at com.zhubajie.framework.test.util.common.CommonInitUtils.commonInit(CommonInitUtils.java:27)
at com.zhubajie.framework.test.util.common.ParamUtils.generateParametersNew(ParamUtils.java:418)
at com.zhubajie.framework.test.util.common.ParamUtils.getParameters(ParamUtils.java:235)
at com.zhubajie.framework.test.BaseDubbo.prepareExecMethod(BaseDubbo.java:214)
at com.zhubajie.framework.test.BaseDubbo.lambda$baseDubbo$3(BaseDubbo.java:204)
at com.zhubajie.framework.test.BaseDubbo.execMethodMulitTimes(BaseDubbo.java:299)
at com.zhubajie.framework.test.BaseDubbo.baseDubbo(BaseDubbo.java:204)
at com.zhubajie.framework.test.BaseDubbo.startRunTest(BaseDubbo.java:192)
at com.zhubajie.framework.test.BaseDubbo.run(BaseDubbo.java:120)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:209)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: com.alibaba.fastjson.JSONException: syntax error, pos 1, json : FALSE
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1381)
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1284)
at com.alibaba.fastjson.serializer.BooleanCodec.deserialze(BooleanCodec.java:75)
... 35 more

cs7cruho

cs7cruho3#

1.2.28是报如下错误
com.alibaba.fastjson.JSONException: syntax error, pos 1, json : FALSE
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1394)
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1301)
at com.alibaba.fastjson.serializer.BooleanCodec.deserialze(BooleanCodec.java:72)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:642)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:350)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:318)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:281)
at com.zhubajie.framework.test.util.common.StringUtils.json2Bean(StringUtils.java:110)
at com.zhubajie.framework.test.util.common.StringUtils.transferMap2Bean(StringUtils.java:243)
at com.zhubajie.framework.test.util.common.CommonInitUtils.commonInit(CommonInitUtils.java:79)
at com.zhubajie.framework.test.util.common.CommonInitUtils.commonInit(CommonInitUtils.java:27)
at com.zhubajie.framework.test.util.common.ParamUtils.generateParametersNew(ParamUtils.java:418)
at com.zhubajie.framework.test.util.common.ParamUtils.getParameters(ParamUtils.java:235)
at com.zhubajie.framework.test.BaseDubbo.prepareExecMethod(BaseDubbo.java:214)
at com.zhubajie.framework.test.BaseDubbo.lambda$baseDubbo$3(BaseDubbo.java:204)
at com.zhubajie.framework.test.BaseDubbo.execMethodMulitTimes(BaseDubbo.java:299)
at com.zhubajie.framework.test.BaseDubbo.baseDubbo(BaseDubbo.java:204)
at com.zhubajie.framework.test.BaseDubbo.startRunTest(BaseDubbo.java:192)
at com.zhubajie.framework.test.BaseDubbo.run(BaseDubbo.java:120)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:209)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

f3temu5u

f3temu5u4#

大写的FALSE不是json规范哦

2fjabf4q

2fjabf4q5#

但是遇到大些TRUE就不会报错

相关问题