Skip to content

Commit ae68293

Browse files
committed
support gson @SerializedName in decoding
1 parent 5389f9a commit ae68293

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/main/java/com/jsoniter/annotation/GsonAnnotationSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public String value() {
4040

4141
@Override
4242
public String[] from() {
43-
return new String[0];
43+
return new String[]{gsonObj.value()};
4444
}
4545

4646
@Override
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.jsoniter;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.annotations.SerializedName;
5+
import com.jsoniter.annotation.GsonAnnotationSupport;
6+
import junit.framework.TestCase;
7+
8+
public class TestGson extends TestCase {
9+
10+
public void setUp() {
11+
GsonAnnotationSupport.enable();
12+
}
13+
14+
public void tearDown() {
15+
GsonAnnotationSupport.disable();
16+
}
17+
18+
public static class TestObject1 {
19+
@SerializedName("field-1")
20+
public String field1;
21+
}
22+
23+
public void test_SerializedName() {
24+
Gson gson = new Gson();
25+
TestObject1 obj = gson.fromJson("{\"field-1\":\"hello\"}", TestObject1.class);
26+
assertEquals("hello", obj.field1);
27+
obj = JsonIterator.deserialize("{\"field-1\":\"hello\"}", TestObject1.class);
28+
assertEquals("hello", obj.field1);
29+
}
30+
}

0 commit comments

Comments
 (0)