Skip to content

Commit

Permalink
fix ctor is null when encoding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
taowen committed Oct 12, 2017
1 parent 5209ce6 commit 0061987
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/jsoniter/spi/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ private void detectStaticFactory(ClassDescriptor desc, List<Method> allMethods)
}

private void detectCtor(ClassDescriptor desc) {
if (desc.ctor == null) {
return;
}
for (Constructor ctor : desc.clazz.getDeclaredConstructors()) {
JsonCreator jsonCreator = getJsonCreator(ctor.getAnnotations());
if (jsonCreator == null) {
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/jsoniter/TestAnnotationJsonProperty.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jsoniter;

import com.jsoniter.annotation.JsonCreator;
import com.jsoniter.annotation.JsonMissingProperties;
import com.jsoniter.annotation.JsonProperty;
import com.jsoniter.fuzzy.StringIntDecoder;
Expand Down Expand Up @@ -141,4 +142,20 @@ public void test_getter_and_setter() throws IOException {
TestObject9 entity = JsonIterator.deserialize(test, TestObject9.class);
assertEquals("hi", entity.getField1());
}

public static class TestObject10 {
public int field;

@JsonCreator
public TestObject10(@JsonProperty("hello") int field) {
this.field = field;
}
}

public void test_creator_with_json_property() {
String input = "{\"hello\":100}";
TestObject10 obj = JsonIterator.deserialize(input, TestObject10.class);
assertEquals(100, obj.field);
assertEquals("{\"field\":100}", JsonStream.serialize(obj));
}
}

0 comments on commit 0061987

Please sign in to comment.