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 2020/04/20 01:20:46 UTC

[GitHub] [servicecomb-java-chassis] xhanthow opened a new issue #1722: 反序列化失败问题

xhanthow opened a new issue #1722:
URL: https://github.com/apache/servicecomb-java-chassis/issues/1722


   用`convertValue`报错:
   ![image](https://user-images.githubusercontent.com/7291995/79705369-03714580-82e8-11ea-8a26-b84dd724a887.png)
   报错信息如下:`Cannot construct instance of `com.huawei.educenter.oms.course.model.ForceRemovalCourseRequest` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{"courseIds":["311497735721202688"],"nextAction":1,"removalReason":"内容有问题"}')
    at [Source: UNKNOWN; line: -1, column: -1]`
   然后我用readValue是可以正常反序列化出来
   ![image](https://user-images.githubusercontent.com/7291995/79705385-18e66f80-82e8-11ea-9d90-f2aaa2dbb77e.png)
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] xhanthow edited a comment on issue #1722: 反序列化失败问题

Posted by GitBox <gi...@apache.org>.
xhanthow edited a comment on issue #1722:
URL: https://github.com/apache/servicecomb-java-chassis/issues/1722#issuecomment-616344240


   补充:
   如图,`value`类型为`String`,这样就会报错。
   ![image](https://user-images.githubusercontent.com/7291995/79721479-f74fad00-8314-11ea-8172-6d24a49211d3.png)
   但是我传`JSONObject`就ok
   ![image](https://user-images.githubusercontent.com/7291995/79721586-3251e080-8315-11ea-8608-0f3511a6f16c.png)
   用的是
   ```
           RestTemplate restTemplate = RestTemplateBuilder.create();
           String body = "{\"courseIds\":[\"311497735721202688\"],\"nextAction\":1,\"removalReason\":\"222\"}";
           // 成功
           HttpEntity entity = new HttpEntity(JSONObject.parseObject(body), httpHeaders);
           // 失败
           // HttpEntity entity = new HttpEntity(body, httpHeaders);
           ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.POST, entity, Object.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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #1722: 反序列化失败问题

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


   后端是一个对象, 在请求的时候, 可以使用 map或者对象实例进行请求。 不能够用 string, 因为 string的 json 字符串包含引号, 比如 : `"{"a":0}"`, 对于一个对象是 `{"a":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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] liubao68 edited a comment on issue #1722: 反序列化失败问题

Posted by GitBox <gi...@apache.org>.
liubao68 edited a comment on issue #1722:
URL: https://github.com/apache/servicecomb-java-chassis/issues/1722#issuecomment-616409825


   后端是一个对象, 在请求的时候, 可以使用 map或者对象实例进行请求。 不能够用 string, 因为 string的 json 字符串包含引号, 比如 : `"{"a":0}"`, 对于一个对象是 `{"a":0"}`
   
   BTW: jsonobject是一个map


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] xhanthow commented on issue #1722: 反序列化失败问题

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


   补充:
   如图,`value`类型为`String`,这样就会报错。
   ![image](https://user-images.githubusercontent.com/7291995/79721479-f74fad00-8314-11ea-8172-6d24a49211d3.png)
   但是我传`JSONObject`就ok
   ![image](https://user-images.githubusercontent.com/7291995/79721586-3251e080-8315-11ea-8608-0f3511a6f16c.png)
   用的是
   ```
           RestTemplate restTemplate = RestTemplateBuilder.create();
           HttpEntity entity = new HttpEntity(JSONObject.parseObject(body), httpHeaders);
           // HttpEntity entity = new HttpEntity(body, httpHeaders);
           ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.POST, entity, Object.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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] xhanthow edited a comment on issue #1722: 反序列化失败问题

Posted by GitBox <gi...@apache.org>.
xhanthow edited a comment on issue #1722:
URL: https://github.com/apache/servicecomb-java-chassis/issues/1722#issuecomment-616344240


   补充:
   如图,`value`类型为`String`,这样就会报错。
   ![image](https://user-images.githubusercontent.com/7291995/79721479-f74fad00-8314-11ea-8172-6d24a49211d3.png)
   但是我传`JSONObject`就ok
   ![image](https://user-images.githubusercontent.com/7291995/79721586-3251e080-8315-11ea-8608-0f3511a6f16c.png)
   用的是
   ```
   RestTemplate restTemplate = RestTemplateBuilder.create();
   String body = "{\"courseIds\":[\"311497735721202688\"],\"nextAction\":1,\"removalReason\":\"222\"}";
   // 成功
   HttpEntity entity = new HttpEntity(JSONObject.parseObject(body), httpHeaders);
   // 失败
   // HttpEntity entity = new HttpEntity(body, httpHeaders);
   ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.POST, entity, Object.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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org