Skip to content

Commit 5b0d67d

Browse files
committed
Merge branch '3.6.x'
2 parents 8e32cd6 + 4e7c16b commit 5b0d67d

File tree

4 files changed

+155
-24
lines changed

4 files changed

+155
-24
lines changed

.claude/project-rules.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,69 @@ Bash("OWNER_GROUP=$(ls -l README.md | awk '{print $3\":\"$4}') && sudo chown $OW
189189
190190
## Git 提交和版本控制规范
191191
192-
### 规则 3: 禁止自动提交代码
192+
### 规则 3: Commit Message 格式规范
193+
194+
**⚠️ 重要规则(CRITICAL):**
195+
196+
本项目的提交信息**必须使用中文作为核心内容**,遵循以下格式:
197+
198+
**标准格式:**
199+
```
200+
<type>: <中文描述>
201+
202+
<可选的详细说明>
203+
204+
🤖 Generated with [Claude Code](https://claude.com/claude-code)
205+
206+
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
207+
```
208+
209+
**Type 类型(使用英文):**
210+
- `feat`: 新功能
211+
- `fix`: Bug 修复
212+
- `docs`: 文档更新
213+
- `style`: 代码格式调整(不影响代码逻辑)
214+
- `refactor`: 重构(既不是新功能也不是 Bug 修复)
215+
- `perf`: 性能优化
216+
- `test`: 测试相关
217+
- `chore`: 构建过程或辅助工具的变动(包括依赖升级)
218+
- `revert`: 回滚之前的提交
219+
220+
**子类型(可选):**
221+
- `chore(deps)`: 依赖升级,格式:`chore(deps): 升级 <package> 到 v<version>`
222+
223+
**示例:**
224+
```bash
225+
# 新功能
226+
feat: 添加用户认证功能
227+
228+
# Bug 修复
229+
fix: 修复登录失败的问题
230+
231+
# 文档更新
232+
docs: 更新 API 文档
233+
234+
# 依赖升级
235+
chore(deps): 升级 fastjson2 到 v2.0.60
236+
237+
# 代码重构
238+
refactor: 重构用户服务模块
239+
240+
# 性能优化
241+
perf: 优化数据库查询性能
242+
243+
# 构建相关
244+
chore: 更新构建脚本
245+
```
246+
247+
**强制要求:**
248+
1. 描述部分**必须使用中文**
249+
2. Type 类型使用英文小写
250+
3. 描述要简洁明了,概括核心变更
251+
4. 多个变更应该分多次提交
252+
5. 必须在提交消息末尾添加 Claude Code 签名
253+
254+
### 规则 4: 禁止自动提交代码
193255
194256
**⚠️ 重要规则(CRITICAL):**
195257
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
/*---------------------------------------------------------------------------------------------
2-
* Copyright (c) 2024 Huawei Technologies Co., Ltd. All rights reserved.
3-
* This file is a part of the ModelEngine Project.
4-
* Licensed under the MIT License. See License.txt in the project root for license information.
5-
*--------------------------------------------------------------------------------------------*/
1+
/*
2+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*/
66

77
package modelengine.fit.value.fastjson;
88

9+
import com.alibaba.fastjson2.JSONException;
910
import com.alibaba.fastjson2.JSONPath;
1011

1112
import modelengine.fitframework.annotation.Component;
@@ -21,15 +22,25 @@
2122
*/
2223
@Component
2324
public class FastJsonValueHandler implements ValueFetcher, ValueSetter {
25+
private static final String $ = "$";
26+
2427
@Override
2528
public Object fetch(Object object, String propertyPath) {
2629
if (object == null) {
2730
return null;
2831
}
29-
if (StringUtils.isBlank(propertyPath)) {
32+
if (isObjectSelf(propertyPath)) {
3033
return object;
31-
} else {
34+
}
35+
if (object instanceof String) {
36+
return null;
37+
}
38+
try {
3239
return JSONPath.eval(object, this.getParsedPath(propertyPath));
40+
} catch (JSONException e) {
41+
throw new IllegalArgumentException(StringUtils.format(
42+
"Failed to fetch value by JSONPath. [propertyPath={0}]",
43+
propertyPath), e);
3344
}
3445
}
3546

@@ -38,20 +49,32 @@ public Object set(Object object, String propertyPath, Object value) {
3849
if (object == null) {
3950
return null;
4051
}
41-
if (StringUtils.isBlank(propertyPath)) {
52+
if (isObjectSelf(propertyPath)) {
4253
return value;
4354
}
44-
JSONPath.set(object, this.getParsedPath(propertyPath), value);
45-
return object;
55+
if (object instanceof String) {
56+
return object;
57+
}
58+
try {
59+
JSONPath.set(object, this.getParsedPath(propertyPath), value);
60+
return object;
61+
} catch (JSONException e) {
62+
throw new IllegalArgumentException(StringUtils.format("Failed to set value by JSONPath. [propertyPath={0}]",
63+
propertyPath), e);
64+
}
65+
}
66+
67+
private static boolean isObjectSelf(String propertyPath) {
68+
return StringUtils.isBlank(propertyPath) || $.equals(propertyPath);
4669
}
4770

4871
private String getParsedPath(String propertyPath) {
49-
if (propertyPath.startsWith("$")) {
72+
if (propertyPath.startsWith($)) {
5073
return propertyPath;
5174
} else if (propertyPath.startsWith("[")) {
52-
return "$" + propertyPath;
75+
return $ + propertyPath;
5376
} else {
54-
return "$." + propertyPath;
77+
return $ + "." + propertyPath;
5578
}
5679
}
5780
}

framework/fit/java/fit-builtin/plugins/fit-value-fastjson/src/test/java/modelengine/fit/value/fastjson/FastJsonValueFetcherTest.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/*---------------------------------------------------------------------------------------------
2-
* Copyright (c) 2024 Huawei Technologies Co., Ltd. All rights reserved.
3-
* This file is a part of the ModelEngine Project.
4-
* Licensed under the MIT License. See License.txt in the project root for license information.
5-
*--------------------------------------------------------------------------------------------*/
1+
/*
2+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*/
66

77
package modelengine.fit.value.fastjson;
88

@@ -79,6 +79,29 @@ void shouldReturnNullGivenPropertyPathIsNotEmpty() {
7979
}
8080
}
8181

82+
@Nested
83+
@DisplayName("当 object 为 JSON 字符串时")
84+
class GivenObjectIsJsonString {
85+
private Object object;
86+
87+
@BeforeEach
88+
void setup() {
89+
this.object = "{\"k1\":{\"k2\":\"v\"}}";
90+
}
91+
92+
@AfterEach
93+
void teardown() {
94+
this.object = null;
95+
}
96+
97+
@Test
98+
@DisplayName("当 propertyPath 不为空时,不自动解析 JSON 字符串")
99+
void shouldReturnNullGivenPropertyPathIsNotEmpty() {
100+
Object actual = FastJsonValueFetcherTest.this.fetcher.fetch(this.object, "k1.k2");
101+
assertThat(actual).isNull();
102+
}
103+
}
104+
82105
@Nested
83106
@DisplayName("当 object 为键值对时")
84107
class GivenObjectIsKeyValuePair {

framework/fit/java/fit-builtin/plugins/fit-value-fastjson/src/test/java/modelengine/fit/value/fastjson/FastJsonValueSetterTest.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/*---------------------------------------------------------------------------------------------
2-
* Copyright (c) 2024 Huawei Technologies Co., Ltd. All rights reserved.
3-
* This file is a part of the ModelEngine Project.
4-
* Licensed under the MIT License. See License.txt in the project root for license information.
5-
*--------------------------------------------------------------------------------------------*/
1+
/*
2+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*/
66

77
package modelengine.fit.value.fastjson;
88

@@ -71,6 +71,29 @@ void shouldReturnReplacedValueGivenPropertyPathIsEmpty() {
7171
}
7272
}
7373

74+
@Nested
75+
@DisplayName("当 object 为 JSON 字符串时")
76+
class GivenObjectIsJsonString {
77+
private Object object;
78+
79+
@BeforeEach
80+
void setup() {
81+
this.object = "{\"k1\":{\"k2\":\"v\"}}";
82+
}
83+
84+
@AfterEach
85+
void teardown() {
86+
this.object = null;
87+
}
88+
89+
@Test
90+
@DisplayName("当 propertyPath 不为空时,不自动解析 JSON 字符串")
91+
void shouldReturnOriginalStringGivenPropertyPathIsNotEmpty() {
92+
Object actual = FastJsonValueSetterTest.this.setter.set(this.object, "k1.k2", "v1");
93+
assertThat(actual).isEqualTo(this.object);
94+
}
95+
}
96+
7497
@Nested
7598
@DisplayName("当 object 为键值对时")
7699
class GivenObjectIsKeyValuePair {

0 commit comments

Comments
 (0)