You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2022/11/01 01:35:36 UTC

[GitHub] [servicecomb-java-chassis] yanghao605 opened a new issue, #3444: ServiceComb-Java-Chassis 支持REST传输方式下的泛型请求参数和返回值,约束条件是否过于严厉

yanghao605 opened a new issue, #3444:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3444

   服务端提供了一个返回值为泛型ClassName<T>的接口后,消费端接收数据有以下两种方式:
   1、消费端需要定义一个与ClassName<T>处于同一包路径下的ClassName<T>来接收数据,否则会出现返回数据类型转换失败
   2、消费端需要定义一个与服务端定义的返回的泛型类型保持一致的接收对象,比如:服务定义返回数据类型为A<String>,客户端则应该定义一个接收数据的类A,其中的数据定义为String方可接收到数据
   错误信息:
   java.util.LinkedHashMap cannot be cast to xxxxx(接收的数据类型)


-- 
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


[GitHub] [servicecomb-java-chassis] yanghao605 closed issue #3444: ServiceComb-Java-Chassis 支持REST传输方式下的泛型请求参数和返回值,约束条件是否过于严厉

Posted by GitBox <gi...@apache.org>.
yanghao605 closed issue #3444: ServiceComb-Java-Chassis 支持REST传输方式下的泛型请求参数和返回值,约束条件是否过于严厉
URL: https://github.com/apache/servicecomb-java-chassis/issues/3444


-- 
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


[GitHub] [servicecomb-java-chassis] yanghao605 commented on issue #3444: ServiceComb-Java-Chassis 支持REST传输方式下的泛型请求参数和返回值,约束条件是否过于严厉

Posted by GitBox <gi...@apache.org>.
yanghao605 commented on issue #3444:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3444#issuecomment-1298186241

   服务端定义如下:
   ```
   @RequestMapping(value = "/post", method = RequestMethod.POST)
   public SimpleResponse<String> getResponse() {
     SimpleResponse<String> rsp = new SimpleResponse<String>("dasfdasf");
     return rsp;
   }
   ```
   SimpleResponse定义如下:
   ```
   package org.apache.test; //包路径
   
   public class SimpleResponse<T> {
     T value;
     public SimpleResponse(T val) {
        value = val;
     }
   }
   ```
   


-- 
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


[GitHub] [servicecomb-java-chassis] yanghao605 commented on issue #3444: ServiceComb-Java-Chassis 支持REST传输方式下的泛型请求参数和返回值,约束条件是否过于严厉

Posted by GitBox <gi...@apache.org>.
yanghao605 commented on issue #3444:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3444#issuecomment-1298190854

   chassis版本是2.6.0


-- 
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


[GitHub] [servicecomb-java-chassis] yanghao605 commented on issue #3444: ServiceComb-Java-Chassis 支持REST传输方式下的泛型请求参数和返回值,约束条件是否过于严厉

Posted by GitBox <gi...@apache.org>.
yanghao605 commented on issue #3444:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3444#issuecomment-1298190281

   消费端:
   情境一:消费端需要定义一个与ClassName处于同一包路径下的ClassName来接收数据,否则会出现返回数据类型转换失败
   消费端SimpleResponse定义如下:
   ```
   package org.apache.test; //包路径
   
   public class SimpleResponse<T> {
     T value;
     public SimpleResponse(T val) {
        value = val;
     }
   }
   ```
   ```
   SimpleResponse<String>rsp = restTemplate.postForObject(url,null, SimpleResponse.class);
   ```
   情境二:消费端需要定义一个与服务端定义的返回的泛型类型保持一致的接收对象,比如:服务定义返回数据类型为A,客户端则应该定义一个接收数据的类A,其中的数据定义为String方可接收到数据
   ```
   package org.apache.test; //包路径
   
   public class SimpleResponse {
     String  value;
     public SimpleResponse(String val) {
        value = val;
     }
   }
   
   ```
   ```
   SimpleResponse rsp = restTemplate.postForObject(url,null, SimpleResponse.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


[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #3444: ServiceComb-Java-Chassis 支持REST传输方式下的泛型请求参数和返回值,约束条件是否过于严厉

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #3444:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3444#issuecomment-1298200880

   泛型的标准用法是这样的:
   
   ```
       template.exchange("/postListObject", HttpMethod.POST, requestEntity,
           new ParameterizedTypeReference<List<SpringmvcBasicResponseModel>>() { })
   ```
   
   使用 `ParameterizedTypeReference` 


-- 
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


[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #3444: ServiceComb-Java-Chassis 支持REST传输方式下的泛型请求参数和返回值,约束条件是否过于严厉

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #3444:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3444#issuecomment-1298074148

   你能提供一下具体例子吗?包括版本信息等。其中你描述的很多内容应该新版本没有这个限制。泛型使用的场景比较多,下面的材料可以作为参考:
   
   * https://servicecomb.apache.org/references/java-chassis/zh_CN/featured-topics/upgrading/1_3_0T2_0_0.html
   * https://servicecomb.apache.org/references/java-chassis/zh_CN/build-provider/interface-constraints.html
   
   


-- 
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


[GitHub] [servicecomb-java-chassis] fanjiwang1992 commented on issue #3444: ServiceComb-Java-Chassis 支持REST传输方式下的泛型请求参数和返回值,约束条件是否过于严厉

Posted by GitBox <gi...@apache.org>.
fanjiwang1992 commented on issue #3444:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3444#issuecomment-1298231072

   @yanghao605 可以在文档上备注说明一下,这个场景还挺多的


-- 
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