You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by "myhaiting (via GitHub)" <gi...@apache.org> on 2024/12/10 00:53:07 UTC
[I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
myhaiting opened a new issue, #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637
### 背景
项目从Servicecomb2.8迁移到Servicecomb3.2.3
### 问题
BigDecimal作为参数或返回值时无法正常解析
#### 1、BigDecimal参数
`
@GetMapping("/demo")
public String echo(@RequestParam BigDecimal v) {
return "ok";
}
`
#### 报错信息
`
Caused by: java.lang.IllegalStateException: failed to find producer parameter in contract, method=ConsumerEndpoint:echo, parameter name=v.
at org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperCreator.processUnknownParameter
`
#### 2、BigDecimal返回值
`
@GetMapping("/demo")
public BigDecimal echo(@RequestParam String v) {
return null;
}
`
#### 报错信息
`
Caused by: java.lang.Error: not support def type: class io.swagger.v3.oas.models.media.NumberSchema
at org.apache.servicecomb.swagger.converter.ConverterMgr.findJavaType(ConverterMgr.java:111)
`
### 预期
应该能正常序列化和反序列化
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2547859442
上述swagger按照理解也是符合swagger语义的,没问题,理解错了。 see: https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "myhaiting (via GitHub)" <gi...@apache.org>.
myhaiting commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2538870597
> > 就是小数用BigDecimal接收,因为计算都是BigDecimal,这样可以少写一个类型转换 主要是原先2.8是正常的,迁移过来就启动不了
>
> 这个接口主要是用于内部调用吗?我问上面的问题主要是关注下前端是怎么调用这个接口的(比如通过HTTP 测试工具, 浏览器等)。 因为需要考虑REST接口方面的兼容。
是的,都是内部调用
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2547617410
`BigDecimal`等作为`query`、`header`参数,还没有确切的序列化方式定义; 作为`body`参数,需要合适的jackson支持即可。 这个需要详细考虑下规格。 参考: https://servicecomb.apache.org/references/java-chassis/zh_CN/build-provider/http-mapping.html
`@RequestParam BigDecimal` 这种用法目前被识别为 `Query参数聚合为POJO对象`, 这显然不是预期的。
还需要再考虑下怎么定义这种场景的序列化表示。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 closed issue #4637: Servicecomb3.0不支持BigDecimal类型
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "myhaiting (via GitHub)" <gi...@apache.org>.
myhaiting commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2535812982
就是小数用BigDecimal接收,因为计算都是BigDecimal,这样可以少写一个类型转换
主要是原先2.8是正常的,迁移过来就启动不了
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2547831570
上述修改方案测试代码的swagger如下。 意味着在servicecomb内部使用 `BigDecimal`和`BigInteger`之间使用是没有问题的。 但是考虑异构框架的互操作(尽管目前没有)的时候,还是会有些语义不清晰。 Open API `number`, `integer`类型无法表示 `BigDecimal`和`BigInteger`, 会存在精度损失。
```
openapi: 3.0.1
info:
title: swagger definition for org.apache.servicecomb.demo.springmvc.server.BigNumberSchema
version: 1.0.0
servers:
- url: /bigNumber
paths:
/decimal:
post:
operationId: bigDecimal
parameters:
- name: decimalHeader
in: header
required: true
schema:
type: number
- name: decimalQuery
in: query
required: true
schema:
type: number
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
decimalForm:
type: number
responses:
"200":
description: response of 200
content:
application/json:
schema:
type: number
application/protobuf:
schema:
type: number
text/plain:
schema:
type: number
/integer:
post:
operationId: bigInteger
parameters:
- name: intHeader
in: header
required: true
schema:
type: integer
- name: intQuery
in: query
required: true
schema:
type: integer
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
intForm:
type: integer
responses:
"200":
description: response of 200
content:
application/json:
schema:
type: integer
application/protobuf:
schema:
type: integer
text/plain:
schema:
type: integer
components: {}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2538863238
> 就是小数用BigDecimal接收,因为计算都是BigDecimal,这样可以少写一个类型转换 主要是原先2.8是正常的,迁移过来就启动不了
这个接口主要是用于内部调用吗?我问上面的问题主要是关注下前端是怎么调用这个接口的(比如通过HTTP 测试工具, 浏览器等)。 因为需要考虑REST接口方面的兼容。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2547806803
你的方案感觉是可行的。 我也是按照你的方案改的。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "myhaiting (via GitHub)" <gi...@apache.org>.
myhaiting commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2547767759
> https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers OpenAPI 数据类型只有 number和integer,无法涵盖 BigInteger和BigDecimal。 如果要支持估计只能采用String类型表示。
我临时修改是这样,不是很规范,但能正常工作:
https://github.com/apache/servicecomb-java-chassis/blob/f46b97e96d209a9f3bb5bb9ab4097e5e05ea910b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/SwaggerUtils.java#L386-L409
改成:
```java
return (cls != String.class
&& cls != Date.class
&& cls != LocalDate.class
&& cls != LocalDateTime.class
&& cls != BigDecimal.class
&& cls != byte[].class
&& cls != File.class
&& !cls.getName().equals("org.springframework.web.multipart.MultipartFile")
&& !Part.class.isAssignableFrom(cls));
```
https://github.com/apache/servicecomb-java-chassis/blob/f46b97e96d209a9f3bb5bb9ab4097e5e05ea910b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/converter/ConverterMgr.java#L62-L86
加了一行
```java
TYPE_FORMAT_MAP.put(genTypeFormatKey("number", ""),
TypeFactory.defaultInstance().constructType(BigDecimal.class));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2547723838
https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers OpenAPI 数据类型只有 number和integer,无法涵盖 BigInteger和BigDecimal。 如果要支持估计只能采用String类型表示。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Servicecomb3.0不支持BigDecimal类型 [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4637:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4637#issuecomment-2535369993
你们前端是怎么调用这个接口的? `?param=333333.3333` 这样?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org