You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/10/12 05:01:32 UTC

[GitHub] [dubbo-hessian-lite] wongoo opened a new issue #38: wrong generic type for decoding

wongoo opened a new issue #38:
URL: https://github.com/apache/dubbo-hessian-lite/issues/38


   for type `List<Integer[]>` , the decoded type will be `List<List>`, which will cause jackson can't serialize the object, and get the error `java.util.ArrayList cannot be cast to [Ljava.lang.Object;`
   
   the following code will regenerate the error:
   ```java
   
   import com.alibaba.com.caucho.hessian.io.HessianInput;
   import com.alibaba.com.caucho.hessian.io.HessianOutput;
   import com.fasterxml.jackson.databind.ObjectMapper;
   
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.List;
   
   public class Test {
   
       public static void main(String[] args) throws IOException {
   
           DemoData data = new DemoData();
           List<Integer[]> list = new ArrayList<>();
           list.add(new Integer[]{1, 2, 3});
           list.add(new Integer[]{4, 5, 6});
           data.setList(list);
   
           data.setInts(new Integer[]{7, 8, 9});
   
           ObjectMapper objectMapper = new ObjectMapper();
           String json = objectMapper.writeValueAsString(data);
           System.out.println(json);
   
           ByteArrayOutputStream out = new ByteArrayOutputStream();
           HessianOutput output = new HessianOutput(out);
           output.writeObject(data);
   
           ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
           HessianInput input = new HessianInput(is);
           Object o = input.readObject();
           System.out.println(o);
   
           json = objectMapper.writeValueAsString(o);
           System.out.println(json);
       }
   
   }
   
   class DemoData implements Serializable {
       Integer[] ints;
       List<Integer[]> list;
   
       public Integer[] getInts() {
           return ints;
       }
   
       public void setInts(Integer[] ints) {
           this.ints = ints;
       }
   
       public List<Integer[]> getList() {
           return list;
       }
   
       public void setList(List<Integer[]> list) {
           this.list = list;
       }
   }
   ```


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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] wongoo commented on issue #38: wrong generic type for decoding

Posted by GitBox <gi...@apache.org>.
wongoo commented on issue #38:
URL: https://github.com/apache/dubbo-hessian-lite/issues/38#issuecomment-706861183


   <img width="336" alt="invalid_hessian_types" src="https://user-images.githubusercontent.com/4519975/95707091-296e1600-0c8b-11eb-8f27-595590bba087.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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org