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

Improve the compatibility of fastjson1-compatible for issue #2673 #2697

Merged
merged 2 commits into from
Jun 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ protected void acceptAny(T object, Object fieldValue, long features) {
}

Object typedFieldValue;
if (fieldValue == null || fieldType == fieldValue.getClass()) {
if (fieldValue == null || fieldType == fieldValue.getClass() || fieldType == Object.class) {
typedFieldValue = fieldValue;
} else {
if (fieldValue instanceof JSONObject) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.alibaba.fastjson2.issue_2600;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* @author 张治保
* @since 2024/6/13
*/
public class Issue2673 {
@Test
void test() {
String jsonStr = "{\r\n"
+ " \"id\":\"01\",\r\n"
+ "\"list\":[1,2,3],"
+ " \"data\":{\r\n"
+ " \"key\":\"test\"\r\n"
+ " }\r\n"
+ "}";
JSONObject json = JSON.parseObject(jsonStr);
Bean bean = JSON.toJavaObject(json, Bean.class);
Assertions.assertDoesNotThrow(() -> (JSONObject) bean.getData());
Assertions.assertDoesNotThrow(() -> (JSONArray) bean.getList());
}

@Getter
@Setter
static class Bean {
private String id;
private Object data;
private Object list;
}
}
Loading