Skip to content

Commit

Permalink
3.2.67
Browse files Browse the repository at this point in the history
  • Loading branch information
noear committed May 10, 2023
1 parent e9c697b commit f9cd460
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<dependency>
<groupId>org.noear</groupId>
<artifactId>snack3</artifactId>
<version>3.2.66</version>
<version>3.2.67</version>
</dependency>
```

Expand Down
3 changes: 3 additions & 0 deletions UPDATE_LOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 3.2.67
* 增加 java record 的参数与字段去重处理

#### 3.2.66
* 增加 Charset 反序化支持

Expand Down
2 changes: 1 addition & 1 deletion snack3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.noear</groupId>
<artifactId>snack3</artifactId>
<version>3.2.66</version>
<version>3.2.67</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
17 changes: 15 additions & 2 deletions snack3/src/main/java/org/noear/snack/to/ObjectToer.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,17 +500,25 @@ public Object analyseBean(Context ctx, ONode o, Object rst, Class<?> clz, Type t
throw new IllegalArgumentException("The constructor missing parameters: " +clz.getName(), e);
}
} else {
//排除字段
Set<String> excNames = null;

if (rst == null) {
if(clzWrap.recordConstructor() == null) {
rst = BeanUtil.newInstance(clz);
}else{
//只有带参数的构造函(像 kotlin data)
//只有带参数的构造函(像 java record, kotlin data)
excNames = new LinkedHashSet<>();
Parameter[] argsP = clzWrap.recordParams();
Object[] argsV = new Object[argsP.length];

for (int j = 0; j < argsP.length; j++) {
Parameter f = argsP[j];
String fieldK = f.getName();

//构造参数有的,进入排除
excNames.add(fieldK);

if (o.contains(fieldK)) {
Class fieldT = f.getType();
Type fieldGt = f.getParameterizedType();
Expand Down Expand Up @@ -538,8 +546,13 @@ public Object analyseBean(Context ctx, ONode o, Object rst, Class<?> clz, Type t
if (f.isDeserialize() == false) {
continue;
}

String fieldK = f.getName();

if(excNames != null && excNames.contains(fieldK)){
continue;
}


if (o.contains(fieldK)) {
Class fieldT = f.type;
Type fieldGt = f.genericType;
Expand Down
2 changes: 1 addition & 1 deletion snack3_demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>org.noear</groupId>
<artifactId>snack3</artifactId>
<version>3.2.66</version>
<version>3.2.67</version>
</dependency>

<!-- <dependency>-->
Expand Down
20 changes: 20 additions & 0 deletions snack3_demo/src/test/java/features/_test5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package features;

import features.test5.A;
import org.junit.Test;
import org.noear.snack.ONode;

/**
* @author noear 2023/5/10 created
*/
public class _test5 {
@Test
public void test() {
String poc = "{\"@type\":\"features.test5.A\"," +
"\"b\":{\"@type\":\"features.test5.B\",\"bList\":\"str1\"}}";
System.out.println(poc);
A o = ONode.deserialize(poc);
System.out.println(o.getB().getbList().size());
assert o.getB().getbList().size() == 1;
}
}
20 changes: 20 additions & 0 deletions snack3_demo/src/test/java/features/test5/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package features.test5;

/**
* @author noear 2023/5/10 created
*/
public class A {
private B b;

public A(B b) {
this.b = b;
}

public B getB() {
return b;
}

public void setB(B b) {
this.b = b;
}
}
22 changes: 22 additions & 0 deletions snack3_demo/src/test/java/features/test5/B.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package features.test5;

import java.util.List;

/**
* @author noear 2023/5/10 created
*/
public class B {
private List<String> bList;

public B(List<String> bList) {
this.bList = bList;
}

public List<String> getbList() {
return bList;
}

public void setbList(List<String> bList) {
this.bList = bList;
}
}
2 changes: 1 addition & 1 deletion 文章_Java_中_Snack3的使用.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Snack3 基于jdk8,80kb大小,非常小巧。
<dependency>
<groupId>org.noear</groupId>
<artifactId>snack3</artifactId>
<version>3.2.66</version>
<version>3.2.67</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion 文章_Snack3_一个新的微型JSON框架.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ONode 即 `One node` 之意;借签了 `Javascript` 所有变量由 `var` 申
<dependency>
<groupId>org.noear</groupId>
<artifactId>snack3</artifactId>
<version>3.2.66</version>
<version>3.2.67</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion 文章_Snack3之Jsonpath使用.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Snack3 是一个支持JSONPath的JSON框架。JSONPath是一个很强大的功
<dependency>
<groupId>org.noear</groupId>
<artifactId>snack3</artifactId>
<version>3.2.66</version>
<version>3.2.67</version>
</dependency>
```

Expand Down

0 comments on commit f9cd460

Please sign in to comment.