[ https://issues.apache.org/jira/browse/SCB-669?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16512352#comment-16512352 ]
ASF GitHub Bot commented on SCB-669: ------------------------------------ liubao68 closed pull request #768: [SCB-669] add extra hashcode into CtTypeJavaType to avoid deserialization problem URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/768 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java index 1ef4cec8e..74c083cb0 100644 --- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java +++ b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java @@ -16,7 +16,10 @@ */ package org.apache.servicecomb.common.javassist; +import java.util.Objects; + import com.fasterxml.jackson.databind.type.SimpleType; +import com.fasterxml.jackson.databind.type.TypeBindings; /** * just a wrapper for CtType @@ -28,7 +31,9 @@ private CtType type; public CtTypeJavaType(CtType type) { - super(CtTypeJavaType.class); + super(CtTypeJavaType.class, TypeBindings.emptyBindings(), null, null, + type == null ? 0 : type.getGenericSignature().hashCode(), + null, null, false); this.type = type; } @@ -46,9 +51,20 @@ public String getGenericSignature() { return type.getGenericSignature(); } - @Override public StringBuilder getGenericSignature(StringBuilder sb) { return sb.append(type.getGenericSignature()); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || !this.getClass().isAssignableFrom(o.getClass())) { + return false; + } + CtTypeJavaType that = (CtTypeJavaType) o; + return Objects.equals(this.getGenericSignature(), that.getGenericSignature()); + } } diff --git a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java b/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java index 46213a316..9ec4ea96c 100644 --- a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java +++ b/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java @@ -45,4 +45,45 @@ public void getGenericSignature() { Assert.assertEquals("Ljava/util/List<Lorg/apache/servicecomb/common/javassist/TestCtTypeJavaType;>;", listJavaType.getGenericSignature()); } + + /** + * The {@link CtTypeJavaType} with different CtType should holds different hash code. + */ + @Test + public void testHashCode() { + JavaType newJavaType = TypeFactory.defaultInstance().constructType(String.class); + CtType newCtType = new CtType(newJavaType); + CtTypeJavaType newCtTypeJavaType = new CtTypeJavaType(newCtType); + Assert.assertNotEquals(ctTypeJavaType.hashCode(), newCtTypeJavaType.hashCode()); + + newJavaType = TypeFactory.defaultInstance().constructType(cls); + newCtType = new CtType(newJavaType); + newCtTypeJavaType = new CtTypeJavaType(newCtType); + Assert.assertEquals(ctTypeJavaType.hashCode(), newCtTypeJavaType.hashCode()); + } + + /** + * The {@link CtTypeJavaType}s holding different type information should not equal to each others. + * While those holding the same type information should be equal. + */ + @Test + public void testEquals() { + JavaType newJavaType = TypeFactory.defaultInstance().constructType(String.class); + CtType newCtType = new CtType(newJavaType); + CtTypeJavaType newCtTypeJavaType = new CtTypeJavaType(newCtType); + Assert.assertNotEquals(ctTypeJavaType, newCtTypeJavaType); + + newJavaType = TypeFactory.defaultInstance().constructType(cls); + newCtType = new CtType(newJavaType); + newCtTypeJavaType = new CtTypeJavaType(newCtType); + Assert.assertEquals(ctTypeJavaType, newCtTypeJavaType); + + // test subClass of CtTypeJavaType + newJavaType = TypeFactory.defaultInstance().constructType(cls); + newCtType = new CtType(newJavaType); + newCtTypeJavaType = new CtTypeJavaType(newCtType) { + private static final long serialVersionUID = 1876189050753964880L; + }; + Assert.assertEquals(ctTypeJavaType, newCtTypeJavaType); + } } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Fix List response body deserialization problem > ---------------------------------------------- > > Key: SCB-669 > URL: https://issues.apache.org/jira/browse/SCB-669 > Project: Apache ServiceComb > Issue Type: Bug > Reporter: YaoHaishi > Assignee: YaoHaishi > Priority: Major > Fix For: service-center-1.0.0-m2 > > Attachments: invokeProviderDirectly.jpg, invokeViaEdgeService.jpg > > > When a provider has a rest operation whose response is List<Pack>, and the > type Pack is like below > {code:java} > public class Pack{ > private String name; > private int i; > // PackageProp is a type defined by user, and it only contains simple java > type > private List<PackageProp> packagePropList; > } > public class PackageProp{ > private String name; > private int j; > private String prop; > } > {code} > We can use postman to invoke the rest operation directly and it works well. > But if we invoke this operation via EdgeService, the response body will be > deserialized in edge unproperly. The edge treat the response List<Pack> as > List<PackageProp>. -- This message was sent by Atlassian JIRA (v7.6.3#76005)