Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Fastjson
Commits
84835dd3
Commit
84835dd3
authored
3 years ago
by
高铁
Browse files
Options
Download
Email Patches
Plain Diff
bug fixed for set list
parent
b1838616
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/com/alibaba/fastjson/parser/deserializer/FieldDeserializer.java
+21
-4
...ibaba/fastjson/parser/deserializer/FieldDeserializer.java
src/test/java/com/alibaba/json/bvt/parser/deser/list/ListFieldTest.java
+16
-0
...com/alibaba/json/bvt/parser/deser/list/ListFieldTest.java
with
37 additions
and
4 deletions
+37
-4
src/main/java/com/alibaba/fastjson/parser/deserializer/FieldDeserializer.java
+
21
-
4
View file @
84835dd3
...
...
@@ -2,8 +2,10 @@ package com.alibaba.fastjson.parser.deserializer;
import
com.alibaba.fastjson.JSONException
;
import
com.alibaba.fastjson.parser.DefaultJSONParser
;
import
com.alibaba.fastjson.parser.ParserConfig
;
import
com.alibaba.fastjson.serializer.BeanContext
;
import
com.alibaba.fastjson.util.FieldInfo
;
import
com.alibaba.fastjson.util.TypeUtils
;
import
java.lang.reflect.*
;
import
java.util.Collection
;
...
...
@@ -221,12 +223,27 @@ public abstract class FieldDeserializer {
/**
* kotlin代理类property的get方法会抛未初始化异常,用set方法直接赋值
*/
private
static
void
degradeValueAssignment
(
Field
field
,
Method
getMethod
,
Object
object
,
Object
value
)
throws
NoSuchMethodException
,
InvocationTargetException
,
IllegalAccessException
{
private
static
boolean
degradeValueAssignment
(
Field
field
,
Method
getMethod
,
Object
object
,
Object
value
)
throws
InvocationTargetException
,
IllegalAccessException
{
if
(
setFieldValue
(
field
,
object
,
value
))
{
return
;
return
true
;
}
Method
setMethod
=
object
.
getClass
().
getDeclaredMethod
(
"set"
+
getMethod
.
getName
().
substring
(
3
),
getMethod
.
getReturnType
());
setMethod
.
invoke
(
object
,
value
);
try
{
Method
setMethod
=
object
.
getClass
()
.
getDeclaredMethod
(
"set"
+
getMethod
.
getName
().
substring
(
3
),
getMethod
.
getReturnType
());
setMethod
.
invoke
(
object
,
value
);
return
true
;
}
catch
(
InvocationTargetException
ignored
)
{
}
catch
(
NoSuchMethodException
ignored
)
{
}
catch
(
IllegalAccessException
ignored
)
{
}
return
false
;
}
private
static
boolean
setFieldValue
(
Field
field
,
Object
object
,
Object
value
)
throws
IllegalAccessException
{
...
...
This diff is collapsed.
Click to expand it.
src/test/java/com/alibaba/json/bvt/parser/deser/list/ListFieldTest.java
0 → 100644
+
16
-
0
View file @
84835dd3
package
com.alibaba.json.bvt.parser.deser.list
;
import
com.alibaba.fastjson.JSON
;
import
junit.framework.TestCase
;
public
class
ListFieldTest
extends
TestCase
{
public
void
test_for_list
()
throws
Exception
{
JSON
.
parseObject
(
"{'data':['a','b']}"
,
TestPojo
.
class
);
}
public
static
class
TestPojo
{
public
java
.
util
.
List
<
String
>
getData
(){
return
null
;
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment