Skip to content

Commit d45b3f2

Browse files
committed
#94 fix JsonProperty not changing fromNames and toNames
1 parent 9a9d94d commit d45b3f2

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,11 @@ private void updateBindingWithJsonProperty(Binding binding, JsonProperty jsonPro
421421
}
422422
String altName = jsonProperty.value();
423423
if (!altName.isEmpty()) {
424-
binding.name = altName;
424+
if (binding.name == null) {
425+
binding.name = altName;
426+
}
427+
binding.fromNames = new String[]{altName};
428+
binding.toNames = new String[]{altName};
425429
}
426430
if (jsonProperty.from().length > 0) {
427431
binding.fromNames = jsonProperty.from();

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public void test_rename() throws IOException {
2323
assertEquals(100, obj.field1);
2424
}
2525

26-
27-
2826
public static class TestObject2 {
2927
@JsonProperty(required = true)
3028
public int field1;
@@ -98,4 +96,29 @@ public void test_specify_property() throws IOException {
9896
assertEquals(Arrays.asList(100), obj.values);
9997
assertEquals(LinkedList.class, obj.values.getClass());
10098
}
99+
100+
public static class TestObject8 {
101+
public String error;
102+
@JsonProperty(value = "rs", required = true)
103+
public boolean result;
104+
@JsonProperty(value = "code",required = true)
105+
public int code2;
106+
107+
@Override
108+
public String toString() {
109+
StringBuilder builder = new StringBuilder();
110+
builder.append("code=");
111+
builder.append(code2);
112+
builder.append(" rs=");
113+
builder.append(result);
114+
return builder.toString();
115+
116+
}
117+
}
118+
119+
public void test_required() throws IOException {
120+
String test ="{\"rs\":true,\"code\":200}";
121+
TestObject8 entity = JsonIterator.deserialize(test, TestObject8.class);
122+
assertEquals(200, entity.code2);
123+
}
101124
}

0 commit comments

Comments
 (0)