Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixed for smartMatchField, #3312 #3316

Merged
merged 1 commit into from
Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bug fixed for smartMatchField, #3312
  • Loading branch information
ZivYan committed Jun 30, 2020
commit 341fc39f1b341ff1574e83c6cf51536cce758fcf
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;
}
}