apache / apache/servicecomb-java-chassis
Jackson解析Enum类型出现异常,未使用InvocationException进行捕获处理
- Dominant language
- Java
- Stars
- 1.9k
- Forks
- 814
- Avg merge
- 8d 23h
- Merged PRs (30d)
- 1
Description
用户提交的请求参数中Enum值不在swagger的yaml约束的范围内,例如swagger的yaml约束operation为“1”或“2”,输入“operation”:“”或“operation”:“3”,EnumDeserializerl类中使用Jackson解析均会均会抛出JsonMappingException异常,但是RestCodec的restToArgs方法未捕获JsonMappingException,只是使用了Exception来捕获异常但并未获取异常的字段,导致使用spi 机制实现ProduceJsonProcessor时,无法获取框架解析异常的字段,我们需要在RestCodec中捕获json异常,以便于使用ProduceJsonProcessor接收并处理,并向用户展示请求参数中导致异常的字段;建议RestCodec.restToArgs()中使用JsonMappingException.getPath().get(i).getFieldName()接收多个path,并使用throw new InvocationException(Status.BAD_REQUEST, ErrorCode.PARAM_INVALID, stb.toString());把异常抛给ProduceJsonProcessor处理 (或使用InvalidFormatException,但是由于主要是枚举类解析会出现异常,所以也可使用JsonMappingException处理)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at RestCodec.restToArgs and trace how EnumDeserializerl's Jackson parsing exception is handled. Check how ProduceJsonProcessor receives errors, then ensure the invalid request field names from JsonMappingException paths are available through InvocationException with BAD_REQUEST and PARAM_INVALID; the issue allows either JsonMappingException or InvalidFormatException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100