[BUG]Issue for excption tips
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
*简要描述您碰到的问题。*
In FASTJSON2 will return the JSONFormat Excption, but in FASTJSON1, it return no default construction Exception. The json format is valid, but only the Domain has no default construction method. So in FASTJSON2 the excption is not correct.
In FASTJSON2:
com.alibaba.fastjson2.JSONException: expect ':', but 44, offset 30, character ", line 1, column 31, fastjson-version 2.0.42 {"choices":[{"finish_reason":"stop","index":0,"message":{"content":"{\"text\":\"Yes, there are several eco-friendly shoe options available. One of them is the Adidas Ultraboost Parley shoes, which are made from recycled plastic collected from the ocean. Another option is the Allbirds Wool Runners, which are made from sustainable and renewable materials.\",\"categories\":[\"shoes\"],\"brands\":[\"Adidas\", \"Allbirds\"],\"products\":[\"Ultraboost Parley\", \"Wool Runners\"],\"price_max\":\"100\",\"price_min\":\"\",\"certain\":\"nope\",\"options\":[\"Adidas Ultraboost Parley\", \"Allbirds Wool Runners\"],\"further_user_typed_in_questions\":\"\"}","function_call":null,"name":null,"role":"assistant"}}],"created":1701314892,"id":"chatcmpl-8QS0iOhirbj4NYUkrchIcuE1IrhNK","model":"gpt-4-32k","object":"chat.completion","usage":{"completion_tokens":126,"prompt_tokens":592,"total_tokens":718}}
at com.alibaba.fastjson2.JSONReaderASCII.readFieldNameHashCode(JSONReaderASCII.java:620)
at com.alibaba.fastjson2.reader.ObjectReaderNoneDefaultConstructor.readObject(ObjectReaderNoneDefaultConstructor.java:248)
at com.alibaba.fastjson2.reader.FieldReaderObject.readFieldValue(FieldReaderObject.java:293)
at com.alibaba.fastjson2.reader.ObjectReaderNoneDefaultConstructor.readObject(ObjectReaderNoneDefaultConstructor.java:312)
at com.alibaba.fastjson2.reader.ObjectReaderImplList.readObject(ObjectReaderImplList.java:614)
at com.alibaba.fastjson2.reader.FieldReaderObject.readFieldValue(FieldReaderObject.java:293)
at com.alibaba.fastjson2.reader.ObjectReaderNoneDefaultConstructor.readObject(ObjectReaderNoneDefaultConstructor.java:312)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:726)
IN FASTJSON1, same code: this exception is correct.
com.alibaba.fastjson.JSONException: default constructor not found. class com.azure.ai.openai.models.ChatCompletions
at com.alibaba.fastjson.util.JavaBeanInfo.build(JavaBeanInfo.java:574)
at com.alibaba.fastjson.parser.ParserConfig.createJavaBeanDeserializer(ParserConfig.java:993)
at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:879)
at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:584)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:696)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:394)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:298)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:588)
### 环境信息
*请填写以下信息:*
- OS信息: 14.2 Beta (23C5047e)
- JDK信息: Openjdk 1.8.0_312
- 版本信息:Fastjson2 2.0.42
### 重现步骤
*如何操作可以重现该问题:*
use JSON.parseObject("{valid json}", XXX.class)
XXX.class have no default construction method, so if you write XXX xxx = new XXX(); it can't compile.
Then you can see the exception will show you JSON format is an error.
### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
return the exception is the Class can't find a default construction method.
### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
Contributor guide
Research direction
Start with JSON.parseObject("{valid json}", XXX.class) and trace the reported path through ObjectReaderNoneDefaultConstructor, FieldReaderObject, and JSONReaderASCII. Compare the Fastjson2 behavior with the Fastjson1 error for a class without a default constructor. Done means invalid constructor availability is reported instead of a misleading JSON format exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100