Skip to content

Commit 0061987

Browse files
committed
fix ctor is null when encoding issue
1 parent 5209ce6 commit 0061987

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/main/java/com/jsoniter/spi/Config.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ private void detectStaticFactory(ClassDescriptor desc, List<Method> allMethods)
343343
}
344344

345345
private void detectCtor(ClassDescriptor desc) {
346+
if (desc.ctor == null) {
347+
return;
348+
}
346349
for (Constructor ctor : desc.clazz.getDeclaredConstructors()) {
347350
JsonCreator jsonCreator = getJsonCreator(ctor.getAnnotations());
348351
if (jsonCreator == null) {

src/test/java/com/jsoniter/TestAnnotationJsonProperty.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.jsoniter;
22

3+
import com.jsoniter.annotation.JsonCreator;
34
import com.jsoniter.annotation.JsonMissingProperties;
45
import com.jsoniter.annotation.JsonProperty;
56
import com.jsoniter.fuzzy.StringIntDecoder;
@@ -141,4 +142,20 @@ public void test_getter_and_setter() throws IOException {
141142
TestObject9 entity = JsonIterator.deserialize(test, TestObject9.class);
142143
assertEquals("hi", entity.getField1());
143144
}
145+
146+
public static class TestObject10 {
147+
public int field;
148+
149+
@JsonCreator
150+
public TestObject10(@JsonProperty("hello") int field) {
151+
this.field = field;
152+
}
153+
}
154+
155+
public void test_creator_with_json_property() {
156+
String input = "{\"hello\":100}";
157+
TestObject10 obj = JsonIterator.deserialize(input, TestObject10.class);
158+
assertEquals(100, obj.field);
159+
assertEquals("{\"field\":100}", JsonStream.serialize(obj));
160+
}
144161
}

0 commit comments

Comments
 (0)