Skip to content

Commit

Permalink
#125 avoid nested JsonException
Browse files Browse the repository at this point in the history
  • Loading branch information
taowen committed Nov 18, 2017
1 parent 40ca712 commit e51faad
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/jsoniter/JsonIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ public static void enableStreamingSupport() {
isStreamingEnabled = true;
try {
DynamicCodegen.enableStreamingSupport();
} catch (JsonException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/jsoniter/ReflectionCollectionDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public ReflectionCollectionDecoder(Class clazz, Type[] typeArgs) {
public Object decode(JsonIterator iter) throws IOException {
try {
return decode_(iter);
} catch (JsonException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/jsoniter/ReflectionMapDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public ReflectionMapDecoder(Class clazz, Type[] typeArgs) {
public Object decode(JsonIterator iter) throws IOException {
try {
return decode_(iter);
} catch (JsonException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/jsoniter/ReflectionObjectDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public String toString() {
public ReflectionObjectDecoder(ClassInfo classInfo) {
try {
init(classInfo);
} catch (JsonException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand Down Expand Up @@ -115,6 +117,8 @@ public class OnlyField implements Decoder {
public Object decode(JsonIterator iter) throws IOException {
try {
return decode_(iter);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand Down Expand Up @@ -178,6 +182,8 @@ public class WithCtor implements Decoder {
public Object decode(JsonIterator iter) throws IOException {
try {
return decode_(iter);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand Down Expand Up @@ -255,6 +261,8 @@ public class WithWrapper implements Decoder {
public Object decode(JsonIterator iter) throws IOException {
try {
return decode_(iter);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public ReflectionObjectEncoder(ClassInfo classInfo) {
public void encode(Object obj, JsonStream stream) throws IOException {
try {
enocde_(obj, stream);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand All @@ -52,6 +54,8 @@ public Any wrap(Object obj) {
Object val = getter.binding.method.invoke(obj);
copied.put(getter.toName, val);
}
} catch (JsonException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/jsoniter/spi/ClassDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ private static Binding createBindingFromField(Map<String, Type> lookup, ClassInf
binding.annotations = field.getAnnotations();
binding.field = field;
return binding;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new JsonException("failed to create binding for field: " + field, e);
}
Expand Down Expand Up @@ -292,6 +294,8 @@ private static List<Binding> getSetters(Map<String, Type> lookup, ClassInfo clas
setter.method = method;
setter.annotations = method.getAnnotations();
setters.add(setter);
} catch (JsonException e) {
throw e;
} catch (Exception e) {
throw new JsonException("failed to create binding from setter: " + method, e);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/jsoniter/spi/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,17 @@ private void updateBindingWithJsonProperty(Binding binding, JsonProperty jsonPro
if (jsonProperty.decoder() != Decoder.class) {
try {
binding.decoder = jsonProperty.decoder().newInstance();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
}
if (jsonProperty.encoder() != Encoder.class) {
try {
binding.encoder = jsonProperty.encoder().newInstance();
} catch (JsonException e) {
throw e;
} catch (Exception e) {
throw new JsonException(e);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/jsoniter/spi/TypeLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ private static String generateCacheKey(Type type, String prefix) {
decoderClassName.append('_');
decoderClassName.append(typeName);
}
} catch (JsonException e) {
throw e;
} catch (Exception e) {
throw new JsonException("failed to generate cache key for: " + type, e);
}
Expand Down

0 comments on commit e51faad

Please sign in to comment.