From 10703aae65424f5930132f95fbd49ccb6e39edf4 Mon Sep 17 00:00:00 2001 From: jwilson Date: Thu, 13 Oct 2016 22:06:41 -0400 Subject: [PATCH] Omit Kotlin and Scala platform types from the class adapter. It's unlikely that these will be stable, or that they'll do anything reasonable. Closes: https://github.com/square/moshi/issues/185 --- .../com/squareup/moshi/ClassJsonAdapter.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.java b/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.java index 472731d..510e30d 100644 --- a/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.java +++ b/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.java @@ -27,9 +27,19 @@ import java.util.Set; import java.util.TreeMap; /** - * Emits a regular class as a JSON object by mapping Java fields to JSON object properties. Fields - * of classes in {@code java.*}, {@code javax.*} and {@code android.*} are omitted from both - * serialization and deserialization unless they are either public or protected. + * Emits a regular class as a JSON object by mapping Java fields to JSON object properties. + * + *

Platform Types

+ * Fields from platform classes are omitted from both serialization and deserialization unless + * they are either public or protected. This includes the following packages and their subpackages: + * + * */ final class ClassJsonAdapter extends JsonAdapter { public static final JsonAdapter.Factory FACTORY = new JsonAdapter.Factory() { @@ -101,9 +111,12 @@ final class ClassJsonAdapter extends JsonAdapter { * types because they're unspecified and likely to be different on Java vs. Android. */ private boolean isPlatformType(Class rawType) { - return rawType.getName().startsWith("java.") - || rawType.getName().startsWith("javax.") - || rawType.getName().startsWith("android."); + String name = rawType.getName(); + return name.startsWith("android.") + || name.startsWith("java.") + || name.startsWith("javax.") + || name.startsWith("kotlin.") + || name.startsWith("scala."); } /** Returns true if fields with {@code modifiers} are included in the emitted JSON. */