我是Kotlin的新手,我仍然不能完全理解一些东西的语法,特别是在lambda中。我正在尝试为uni项目构建一个简单的REST api,目前正在处理ktor、exposed和moshi。然而,我得到了以下错误: java.lang.IllegalArgumentException: No JsonAdapter for class java.util.ArrayList, you should probably use List instead of ArrayList (Moshi only supports the collection interfaces by default) or
在以下Url中引用我的问题:将minsdk更改为26并在android 9上使用仿真器后,出现以下错误 E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-4
Process: com.app.homecraft, PID: 28831
java.lang.IllegalArgumentException: Platform class java.time.LocalDateTime (with no annotations) requires explicit JsonAdapter to be regis
升级到 (从)后,我将遇到以下崩溃和堆栈跟踪:
java.lang.IllegalArgumentException: Cannot serialize Kotlin type com.garpr.android.data.models.RankedPlayer. Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapter from the moshi-kotlin artif
我目前正在开发一些基本的应用程序,我试图从API -对象列表中获得响应。 我的数据类是: @JsonClass(generateAdapter = true)
data class Tag(
@Json(name = "id")
val id: Int,
@Json(name = "name")
val name: String
)
@JsonClass(generateAdapter = true)
data class Test(
@Json(name = "count")
val coun
我试图使用用于Android的Moshi库将JSON字符串转换为Java对象。对象包含类型为
ArrayList<String>
在应用程序运行之后,抛出以下异常
Caused by: java.lang.IllegalArgumentException: Platform java.util.ArrayList<java.lang.String> (with no annotations) requires explicit JsonAdapter to be registered
for java.util.ArrayList<java.lang.Strin
我有个奇怪的问题。当在R8中使用minify/困惑时,我有以下错误
java.lang.IllegalArgumentException: Cannot serialize Kotlin type <omitted>auth.model.ErrorResponse. Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapter from the moshi-kotli
我在这里的最终目标是声明以下改进界面:
interface SomeService {
@GET("/path")
fun getSomethingFlow() : Flow<DataState<SomeApiDataClass>>
}
data class DataState<T>(val data : T, state: State)
// the real data class is a big bigger, but that's the idea
// state is an enum
其意图是我的CallAdap
我有一个由Gradle和Kotlin组成的项目。它是一个命令行实用程序,我希望能够从我的终端运行生成的jar。但是,我得到了以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
at com.autentia.impt.MainKt.main(Main.kt)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
at java.
当我遇到这个错误时,我正与Moshi一起从一个API中提取JSON数据并将其映射到我的DTO数据类:
致命例外:主进程: com.squareup.moshi.kotlin.reflect.KotlinJsonAdapter.fromJson(KotlinJsonAdapter.kt:103) at com.squareup.moshi.kotlin.reflect.KotlinJsonAdapter.fromJson(KotlinJsonAdapter.kt:103) at com.squareup.moshi.internal.NullSafeJsonAdapter.fromJson(N
我有一个混合Java和Kotlin的应用程序。在Kotlin代码中,我使用Moshi在转换器中为Room数据库表将一个对象转换为Json。
我有一种情况工作得很好,但另一种情况会产生错误:
Not enough information to infer type variable T
这就是我的代码的样子:
val type: Type = Types.newParameterizedType(
MutableMap::class.java,
LayerTwoConn::class.java,
TWeFiState::class.
当前在PolymorphicJsonAdapterFactory和Kotlins密封类方面有问题。我有一个返回多态home组件的API,我试图使用Kotlin中的Moshi来解析和创建多态对象,但我得到了以下错误: Caused by: java.lang.IllegalArgumentException: Cannot serialize abstract class home.HomeComponent
for class home.HomeComponent
for java.util.List<home.HomeComponent> components
for cl
它在kotlin 1.4.31上工作得很好。在将kotlin升级到1.5.20之后,当我启动应用程序时,它总是会崩溃。错误是
kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Unresolved class: class d.e.i.h.m$b
at kotlin.reflect.jvm.internal.KClassImpl.reportUnresolvedClass(KClassImpl.kt:329)
at kotlin.reflect.jvm.internal.KClassImpl.access$re
我试图使用Moshi + kotlin解析一个设计不太好的api的json。出于某些原因,它将71这样的数字解析为双倍。
第三方api有一个对象列表,这些对象可以是:{"foo":[1234567000,12]} // long,int或{"foo":[1234567000,"string",0,2]} / long,string,int,int
由于第三方api,我有以下kotlin类:
@JsonClass(generateAdapter = true)
class D {
var foo: List<Any> // I
假设我们有以下模型 open class Orden(@field:Json(name = "vehiculo_id") var vehiculo_id: IdNameItem = IdNameItem()) :
RealmObject()
open class IdNameItem(
@field:Json(name = "id") var id: Long = 0,
@field:Json(name = "name") var name: String = "" ):RealmObject() 我们想要从WS获取所有Ord
我是kotlin-android开发公司的一名新蜜蜂。
我想解析一个JSON,比如
{
"name": "This is my name",
}
定义为Foo类的
Foo.kt
@JsonClass(generateAdapter = true)
data class Foo(val name: String)
这个Foo类文件按照下面的代码生成代码。
FooJsonAdapter.kt (由码元生成)
class FooJsonAdapter(moshi: Moshi) : JsonAdapter<Foo>() {
private va
我有以下依赖关系:
moshi-码原: 1.10.0
kotlin: 1.4.10
Android Gradle插件: 4.0.1
在构建中启用了R8。
在运行时,当Moshi尝试解析枚举时,我得到了以下堆栈跟踪
java.lang.AssertionError: Missing field in e.f.a.k.c.b.a
at com.squareup.moshi.StandardJsonAdapters$EnumJsonAdapter.<init>(SourceFile:246)
at com.squareup.moshi.StandardJs
我按照添加了对moshi和pro卫士规则的gradle依赖,然后编写代码进行验证。
data class Car(
@Json(name = "low_speed") val lowSpeed: Int,
@Json(name = "high_speed") val highSpeed: Int
)
val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()
val jsonAdapter = moshi.adapte
在我的安卓应用程序的Fragment中,我使用SharedPreferences和Moshi来保存和加载我从RecyclerView获得的数据。
以下是我为该任务提供的两个函数:
private fun saveData() {
val sharedPreferences = this@Main.requireContext().getSharedPreferences("recycler_view", Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()
val moshi = Mosh
您好,我刚刚将Android Studio更新到3.2 canary 2,我的项目编译良好,但我有一个运行时异常。
下面是崩溃的原因:
FATAL EXCEPTION: main
Process: fr.myApp, PID: 12658
java.lang.VerifyError: Rejecting class kotlin.reflect.jvm.internal.KClassImpl that attempts to sub-class erroneous class kotlin.reflect.jvm.internal.KDeclarationContainerImpl (decl