mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Refuse kotlin classes in ClassJsonAdapter (#749)
* Refuse kotlin classes in ClassJsonAdapter * Fail() * Tweak message
This commit is contained in:
@@ -75,6 +75,14 @@ final class ClassJsonAdapter<T> extends JsonAdapter<T> {
|
||||
if (Modifier.isAbstract(rawType.getModifiers())) {
|
||||
throw new IllegalArgumentException("Cannot serialize abstract class " + rawType.getName());
|
||||
}
|
||||
for (Annotation annotation : rawType.getDeclaredAnnotations()) {
|
||||
if ("kotlin.Metadata".equals(annotation.annotationType().getName())) {
|
||||
throw new IllegalArgumentException("Cannot serialize Kotlin type " + rawType.getName()
|
||||
+ ". Reflective serialization of Kotlin classes without using kotlin-reflect has "
|
||||
+ "undefined and unexpected behavior. Please use KotlinJsonAdapter from the "
|
||||
+ "moshi-kotlin artifact or use code gen from the moshi-kotlin-codegen artifact.");
|
||||
}
|
||||
}
|
||||
|
||||
ClassFactory<Object> classFactory = ClassFactory.get(rawType);
|
||||
Map<String, FieldBinding<?>> fields = new TreeMap<>();
|
||||
|
Reference in New Issue
Block a user