Skip to content

Commit 14df4e8

Browse files
committed
fix issue on android
1 parent d34a2ad commit 14df4e8

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ private static List<Binding> getFields(Map<String, Type> lookup, Class clazz, bo
278278
if (Modifier.isStatic(field.getModifiers())) {
279279
continue;
280280
}
281+
if (Modifier.isTransient(field.getModifiers())) {
282+
continue;
283+
}
281284
if (includingPrivate) {
282285
field.setAccessible(true);
283286
}
@@ -288,12 +291,16 @@ private static List<Binding> getFields(Map<String, Type> lookup, Class clazz, bo
288291
}
289292

290293
private static Binding createBindingFromField(Map<String, Type> lookup, Class clazz, Field field) {
291-
Binding binding = new Binding(clazz, lookup, field.getGenericType());
292-
binding.fromNames = new String[]{field.getName()};
293-
binding.name = field.getName();
294-
binding.annotations = field.getAnnotations();
295-
binding.field = field;
296-
return binding;
294+
try {
295+
Binding binding = new Binding(clazz, lookup, field.getGenericType());
296+
binding.fromNames = new String[]{field.getName()};
297+
binding.name = field.getName();
298+
binding.annotations = field.getAnnotations();
299+
binding.field = field;
300+
return binding;
301+
} catch (Exception e) {
302+
throw new JsonException("failed to create binding for field: " + field, e);
303+
}
297304
}
298305

299306
private static List<Field> getAllFields(Class clazz, boolean includingPrivate) {
@@ -338,13 +345,17 @@ private static List<Binding> getSetters(Map<String, Type> lookup, Class clazz, b
338345
if (includingPrivate) {
339346
method.setAccessible(true);
340347
}
341-
String fromName = translateSetterName(methodName);
342-
Binding binding = new Binding(clazz, lookup, paramTypes[0]);
343-
binding.fromNames = new String[]{fromName};
344-
binding.name = fromName;
345-
binding.method = method;
346-
binding.annotations = method.getAnnotations();
347-
setters.add(binding);
348+
try {
349+
String fromName = translateSetterName(methodName);
350+
Binding binding = new Binding(clazz, lookup, paramTypes[0]);
351+
binding.fromNames = new String[]{fromName};
352+
binding.name = fromName;
353+
binding.method = method;
354+
binding.annotations = method.getAnnotations();
355+
setters.add(binding);
356+
} catch (Exception e) {
357+
throw new JsonException("failed to create binding from setter: " + method, e);
358+
}
348359
}
349360
return setters;
350361
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ public int hashCode() {
5353

5454
@Override
5555
public String toString() {
56+
String rawTypeName = rawType.toString();
57+
if (rawType instanceof Class) {
58+
Class clazz = (Class) rawType;
59+
rawTypeName = clazz.getName();
60+
}
5661
return "ParameterizedTypeImpl{" +
5762
"actualTypeArguments=" + Arrays.toString(actualTypeArguments) +
5863
", ownerType=" + ownerType +
59-
", rawType=" + rawType +
64+
", rawType=" + rawTypeName +
6065
'}';
6166
}
6267

0 commit comments

Comments
 (0)