Skip to content

Commit

Permalink
Merge pull request #3316 from ZivYan/Issue#3312
Browse files Browse the repository at this point in the history
bug fixed for smartMatchField, #3312
  • Loading branch information
wenshao committed Jul 4, 2020
2 parents db880f5 + 341fc39 commit e4c86bb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1307,16 +1307,16 @@ public FieldDeserializer smartMatch(String key, int[] setFlags) {
}

// smartMatchHashArrayMapping
long smartKeyHash = TypeUtils.fnv1a_64_extract(key);
long smartKeyHash = TypeUtils.fnv1a_64_lower(key);
int pos = Arrays.binarySearch(smartMatchHashArray, smartKeyHash);
if (pos < 0) {
long smartKeyHash1 = TypeUtils.fnv1a_64_lower(key);
long smartKeyHash1 = TypeUtils.fnv1a_64_extract(key);
pos = Arrays.binarySearch(smartMatchHashArray, smartKeyHash1);
}

boolean is = false;
if (pos < 0 && (is = key.startsWith("is"))) {
smartKeyHash = TypeUtils.fnv1a_64_lower(key.substring(2));
smartKeyHash = TypeUtils.fnv1a_64_extract(key.substring(2));
pos = Arrays.binarySearch(smartMatchHashArray, smartKeyHash);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/alibaba/fastjson/util/FieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ public FieldInfo(String name, //
private long nameHashCode64(String name, JSONField annotation)
{
if (annotation != null && annotation.name().length() != 0) {
return TypeUtils.fnv1a_64_extract(name);
return TypeUtils.fnv1a_64_lower(name);
}
return TypeUtils.fnv1a_64_lower(name);
return TypeUtils.fnv1a_64_extract(name);
}

protected char[] genFieldNameChars() {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/alibaba/fastjson/util/TypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2901,7 +2901,7 @@ public static float parseFloat(String str) {
return Float.parseFloat(str);
}

public static long fnv1a_64_lower(String key){
public static long fnv1a_64_extract(String key){
long hashCode = 0xcbf29ce484222325L;
for(int i = 0; i < key.length(); ++i){
char ch = key.charAt(i);
Expand All @@ -2917,10 +2917,13 @@ public static long fnv1a_64_lower(String key){
return hashCode;
}

public static long fnv1a_64_extract(String key){
public static long fnv1a_64_lower(String key){
long hashCode = 0xcbf29ce484222325L;
for(int i = 0; i < key.length(); ++i){
char ch = key.charAt(i);
if(ch >= 'A' && ch <= 'Z'){
ch = (char) (ch + 32);
}
hashCode ^= ch;
hashCode *= 0x100000001b3L;
}
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_3300/Issue3313.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.alibaba.json.bvt.issue_3300;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import junit.framework.TestCase;
import lombok.Data;
import org.springframework.util.Assert;

/**
* @Author :Nanqi
* @Date :Created in 21:54 2020/6/30
*/
public class Issue3313 extends TestCase {
public void test_for_issue() throws Exception {
String jsonStr = "{\"NAME\":\"nanqi\",\"age\":18}";
Model model = JSONObject.parseObject(jsonStr, Model.class);
Assert.notNull(model.getAGe());
Assert.notNull(model.getName());
}

@Data
static class Model {
@JSONField(name = "NaMe")
private String name;

@JSONField(name = "age")
private Integer aGe;
}
}

0 comments on commit e4c86bb

Please sign in to comment.