Skip to content

Commit

Permalink
cut 0.9.18
Browse files Browse the repository at this point in the history
  • Loading branch information
taowen committed Nov 18, 2017
1 parent 8f5d181 commit 21513c1
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 11 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# 0.9.18
* fix of overflow detection for numeric primitive types
* fix of method prefix of error message
* issue #125 avoid nested JsonException
* fix #109 treat wildcard generics variable as Object

# 0.9.17
* fix leading zero
* fix #112 #119
* fix of parsing zero & min values
* issue #115 better leading zero detection
* fix #144, parse max int/long
* fix #110 if @JsonProperty is marked on field, ignore getter/setter

# 0.9.16

* issue #107 annotation should be marked on getter/setter if present
* fix ctor is null when encoding issue
* issue #104, JsonWrapper argument should not be mandatory
* issue #99 added mustBeValid method to Any class
* issue #97 demonstrate JsonProperty when both field and setter
* like "1.0e+10" should not fail
* issue #94 skip transient field
* issue #94 fix JsonProperty not changing fromNames and toNames
* issue #93 some control character should be esacped specially
* issue #93 fix control character serialization
* issue #92 fix generics support

# 0.9.15

breaking changes
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jsoniter</groupId>
<version>0.9.18-SNAPSHOT</version>
<version>0.9.18</version>
<artifactId>jsoniter</artifactId>
<name>json iterator</name>
<description>jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go</description>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jsoniter/Codegen.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static Type chooseImpl(Type type) {
clazz = (Class) pType.getRawType();
typeArgs = pType.getActualTypeArguments();
} else if (type instanceof WildcardType) {
clazz = Object.class;
return Object.class;
} else {
clazz = (Class) type;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/jsoniter/CodegenImplNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
Expand Down Expand Up @@ -177,6 +178,8 @@ public static String getTypeName(Type fieldType) {
ParameterizedType pType = (ParameterizedType) fieldType;
Class clazz = (Class) pType.getRawType();
return clazz.getCanonicalName();
} else if (fieldType instanceof WildcardType) {
return Object.class.getCanonicalName();
} else {
throw new JsonException("unsupported type: " + fieldType);
}
Expand Down Expand Up @@ -204,6 +207,8 @@ private static String genReadOp(String cacheKey, Type valueType) {
if (nativeRead != null) {
return nativeRead;
}
} else if (valueType instanceof WildcardType) {
return NATIVE_READS.get(Object.class.getCanonicalName());
}
Codegen.getDecoder(cacheKey, valueType);
if (Codegen.canStaticAccess(cacheKey)) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jsoniter/output/Codegen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.util.*;

class Codegen {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/jsoniter/output/CodegenImplNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
Expand Down Expand Up @@ -282,6 +283,10 @@ public static void genWriteOp(CodegenResult ctx, String code, Type valueType, bo
ctx.append(String.format("stream.writeVal((%s)%s);", getTypeName(valueType), code));
return;
}
if (valueType instanceof WildcardType) {
ctx.append(String.format("stream.writeVal((%s)%s);", getTypeName(Object.class), code));
return;
}
}

if (!isCollectionValueNullable) {
Expand Down Expand Up @@ -313,6 +318,8 @@ public static String getTypeName(Type fieldType) {
ParameterizedType pType = (ParameterizedType) fieldType;
Class clazz = (Class) pType.getRawType();
return clazz.getCanonicalName();
} else if (fieldType instanceof WildcardType) {
return Object.class.getCanonicalName();
} else {
throw new JsonException("unsupported type: " + fieldType);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/jsoniter/spi/ClassDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ private static Map<String, Type> collectTypeVariableLookup(Type type) {
vars.putAll(collectTypeVariableLookup(clazz.getGenericSuperclass()));
return vars;
}
if (type instanceof WildcardType) {
return vars;
}
throw new JsonException("unexpected type: " + type);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jsoniter/spi/TypeLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static String generateCacheKey(Type type, String prefix) {
decoderClassName.append(formatTypeWithoutSpecialCharacter(compType));
decoderClassName.append("_array");
} else if (type instanceof WildcardType) {
decoderClassName.append("_wildcard");
decoderClassName.append(Object.class.getName());
} else {
throw new UnsupportedOperationException("do not know how to handle: " + type);
}
Expand All @@ -148,7 +148,7 @@ private static String formatTypeWithoutSpecialCharacter(Type type) {
return formatTypeWithoutSpecialCharacter(gaType.getGenericComponentType()) + "_array";
}
if (type instanceof WildcardType) {
return type.toString();
return Object.class.getCanonicalName();
}
throw new JsonException("unsupported type: " + type + ", of class " + type.getClass());
}
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/com/jsoniter/TestGenerics.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.jsoniter;

import com.jsoniter.output.JsonStream;
import com.jsoniter.spi.Binding;
import com.jsoniter.spi.ClassDescriptor;
import com.jsoniter.spi.ClassInfo;
import com.jsoniter.spi.TypeLiteral;
import com.jsoniter.spi.*;
import junit.framework.TestCase;

import java.io.IOException;
Expand All @@ -15,7 +11,7 @@
public class TestGenerics extends TestCase {

static {
// JsonIterator.setMode(DecodingMode.REFLECTION_MODE);
// JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_STRICTLY);
}

public void test_int_list() throws IOException {
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/com/jsoniter/output/TestGenerics.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestGenerics extends TestCase {
static {
Expand Down Expand Up @@ -39,13 +41,17 @@ public void test_inherited_getter_is_not_duplicate() throws IOException {

public static class TestObject7 {
public List<?> field;
public Map<?,?> field2;
}

public void test_wildcard() throws IOException {
TestObject7 obj = new TestObject7();
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
obj.field = list;
assertEquals("{\"field\":[1]}", JsonStream.serialize(obj));
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("hello", 1);
obj.field2 = map;
assertEquals("{\"field\":[1],\"field2\":{\"hello\":1}}", JsonStream.serialize(obj));
}
}

0 comments on commit 21513c1

Please sign in to comment.