Skip to content

Commit 21513c1

Browse files
committedNov 18, 2017
cut 0.9.18
1 parent 8f5d181 commit 21513c1

File tree

10 files changed

+57
-11
lines changed

10 files changed

+57
-11
lines changed
 

‎CHANGELOG.md

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
# 0.9.18
2+
* fix of overflow detection for numeric primitive types
3+
* fix of method prefix of error message
4+
* issue #125 avoid nested JsonException
5+
* fix #109 treat wildcard generics variable as Object
6+
7+
# 0.9.17
8+
* fix leading zero
9+
* fix #112 #119
10+
* fix of parsing zero & min values
11+
* issue #115 better leading zero detection
12+
* fix #144, parse max int/long
13+
* fix #110 if @JsonProperty is marked on field, ignore getter/setter
14+
15+
# 0.9.16
16+
17+
* issue #107 annotation should be marked on getter/setter if present
18+
* fix ctor is null when encoding issue
19+
* issue #104, JsonWrapper argument should not be mandatory
20+
* issue #99 added mustBeValid method to Any class
21+
* issue #97 demonstrate JsonProperty when both field and setter
22+
* like "1.0e+10" should not fail
23+
* issue #94 skip transient field
24+
* issue #94 fix JsonProperty not changing fromNames and toNames
25+
* issue #93 some control character should be esacped specially
26+
* issue #93 fix control character serialization
27+
* issue #92 fix generics support
28+
129
# 0.9.15
230

331
breaking changes

‎pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.jsoniter</groupId>
6-
<version>0.9.18-SNAPSHOT</version>
6+
<version>0.9.18</version>
77
<artifactId>jsoniter</artifactId>
88
<name>json iterator</name>
99
<description>jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go</description>

‎src/main/java/com/jsoniter/Codegen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static Type chooseImpl(Type type) {
129129
clazz = (Class) pType.getRawType();
130130
typeArgs = pType.getActualTypeArguments();
131131
} else if (type instanceof WildcardType) {
132-
clazz = Object.class;
132+
return Object.class;
133133
} else {
134134
clazz = (Class) type;
135135
}

‎src/main/java/com/jsoniter/CodegenImplNative.java

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.IOException;
77
import java.lang.reflect.ParameterizedType;
88
import java.lang.reflect.Type;
9+
import java.lang.reflect.WildcardType;
910
import java.math.BigDecimal;
1011
import java.math.BigInteger;
1112
import java.util.HashMap;
@@ -177,6 +178,8 @@ public static String getTypeName(Type fieldType) {
177178
ParameterizedType pType = (ParameterizedType) fieldType;
178179
Class clazz = (Class) pType.getRawType();
179180
return clazz.getCanonicalName();
181+
} else if (fieldType instanceof WildcardType) {
182+
return Object.class.getCanonicalName();
180183
} else {
181184
throw new JsonException("unsupported type: " + fieldType);
182185
}
@@ -204,6 +207,8 @@ private static String genReadOp(String cacheKey, Type valueType) {
204207
if (nativeRead != null) {
205208
return nativeRead;
206209
}
210+
} else if (valueType instanceof WildcardType) {
211+
return NATIVE_READS.get(Object.class.getCanonicalName());
207212
}
208213
Codegen.getDecoder(cacheKey, valueType);
209214
if (Codegen.canStaticAccess(cacheKey)) {

‎src/main/java/com/jsoniter/output/Codegen.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.lang.reflect.Modifier;
1111
import java.lang.reflect.ParameterizedType;
1212
import java.lang.reflect.Type;
13+
import java.lang.reflect.WildcardType;
1314
import java.util.*;
1415

1516
class Codegen {

‎src/main/java/com/jsoniter/output/CodegenImplNative.java

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.IOException;
88
import java.lang.reflect.ParameterizedType;
99
import java.lang.reflect.Type;
10+
import java.lang.reflect.WildcardType;
1011
import java.math.BigDecimal;
1112
import java.math.BigInteger;
1213
import java.util.HashMap;
@@ -282,6 +283,10 @@ public static void genWriteOp(CodegenResult ctx, String code, Type valueType, bo
282283
ctx.append(String.format("stream.writeVal((%s)%s);", getTypeName(valueType), code));
283284
return;
284285
}
286+
if (valueType instanceof WildcardType) {
287+
ctx.append(String.format("stream.writeVal((%s)%s);", getTypeName(Object.class), code));
288+
return;
289+
}
285290
}
286291

287292
if (!isCollectionValueNullable) {
@@ -313,6 +318,8 @@ public static String getTypeName(Type fieldType) {
313318
ParameterizedType pType = (ParameterizedType) fieldType;
314319
Class clazz = (Class) pType.getRawType();
315320
return clazz.getCanonicalName();
321+
} else if (fieldType instanceof WildcardType) {
322+
return Object.class.getCanonicalName();
316323
} else {
317324
throw new JsonException("unsupported type: " + fieldType);
318325
}

‎src/main/java/com/jsoniter/spi/ClassDescriptor.java

+3
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ private static Map<String, Type> collectTypeVariableLookup(Type type) {
391391
vars.putAll(collectTypeVariableLookup(clazz.getGenericSuperclass()));
392392
return vars;
393393
}
394+
if (type instanceof WildcardType) {
395+
return vars;
396+
}
394397
throw new JsonException("unexpected type: " + type);
395398
}
396399

‎src/main/java/com/jsoniter/spi/TypeLiteral.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private static String generateCacheKey(Type type, String prefix) {
122122
decoderClassName.append(formatTypeWithoutSpecialCharacter(compType));
123123
decoderClassName.append("_array");
124124
} else if (type instanceof WildcardType) {
125-
decoderClassName.append("_wildcard");
125+
decoderClassName.append(Object.class.getName());
126126
} else {
127127
throw new UnsupportedOperationException("do not know how to handle: " + type);
128128
}
@@ -148,7 +148,7 @@ private static String formatTypeWithoutSpecialCharacter(Type type) {
148148
return formatTypeWithoutSpecialCharacter(gaType.getGenericComponentType()) + "_array";
149149
}
150150
if (type instanceof WildcardType) {
151-
return type.toString();
151+
return Object.class.getCanonicalName();
152152
}
153153
throw new JsonException("unsupported type: " + type + ", of class " + type.getClass());
154154
}

‎src/test/java/com/jsoniter/TestGenerics.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.jsoniter;
22

3-
import com.jsoniter.output.JsonStream;
4-
import com.jsoniter.spi.Binding;
5-
import com.jsoniter.spi.ClassDescriptor;
6-
import com.jsoniter.spi.ClassInfo;
7-
import com.jsoniter.spi.TypeLiteral;
3+
import com.jsoniter.spi.*;
84
import junit.framework.TestCase;
95

106
import java.io.IOException;
@@ -15,7 +11,7 @@
1511
public class TestGenerics extends TestCase {
1612

1713
static {
18-
// JsonIterator.setMode(DecodingMode.REFLECTION_MODE);
14+
// JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_STRICTLY);
1915
}
2016

2117
public void test_int_list() throws IOException {

‎src/test/java/com/jsoniter/output/TestGenerics.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import java.io.ByteArrayOutputStream;
66
import java.io.IOException;
77
import java.util.ArrayList;
8+
import java.util.HashMap;
89
import java.util.List;
10+
import java.util.Map;
911

1012
public class TestGenerics extends TestCase {
1113
static {
@@ -39,13 +41,17 @@ public void test_inherited_getter_is_not_duplicate() throws IOException {
3941

4042
public static class TestObject7 {
4143
public List<?> field;
44+
public Map<?,?> field2;
4245
}
4346

4447
public void test_wildcard() throws IOException {
4548
TestObject7 obj = new TestObject7();
4649
ArrayList<Integer> list = new ArrayList<Integer>();
4750
list.add(1);
4851
obj.field = list;
49-
assertEquals("{\"field\":[1]}", JsonStream.serialize(obj));
52+
HashMap<String, Object> map = new HashMap<String, Object>();
53+
map.put("hello", 1);
54+
obj.field2 = map;
55+
assertEquals("{\"field\":[1],\"field2\":{\"hello\":1}}", JsonStream.serialize(obj));
5056
}
5157
}

0 commit comments

Comments
 (0)
Please sign in to comment.