У меня есть:
Код: Выделить всё
@Entity(tableName = "messages")
@TypeConverters(
ChatMessageContentConverter::class
)
data class MessageEntity(
@PrimaryKey(autoGenerate = false)
val id: String,
val threadId: String,
val content: ChatMessageContent? = null,
val senderDisplayName: String? = null
)
Код: Выделить всё
class ChatMessageContentConverter {
private val gson = Gson()
@TypeConverter
fun toChatMessageContent(value: String?): ChatMessageContent? {
return value?.let { gson.fromJson(value, ChatMessageContent::class.java) }
}
@TypeConverter
fun fromChatMessageContent(content: ChatMessageContent?): String? {
return content?.let { gson.toJson(content) }
}
}
Код: Выделить всё
error: java.lang.RuntimeException: Unable to create instance of class com.azure.android.communication.common.CommunicationIdentifier. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.
Код: Выделить всё
public final class ChatMessageContent {
@JsonProperty("message")
private String message;
@JsonProperty("topic")
private String topic;
@JsonProperty("participants")
private List participants;
@JsonProperty("initiatorCommunicationIdentifier")
private CommunicationIdentifier initiatorCommunicationIdentifier;
public ChatMessageContent() {
}
public String getMessage() {
return this.message;
}
public ChatMessageContent setMessage(String message) {
this.message = message;
return this;
}
public String getTopic() {
return this.topic;
}
public ChatMessageContent setTopic(String topic) {
this.topic = topic;
return this;
}
public List getParticipants() {
return this.participants;
}
public ChatMessageContent setParticipants(List participants) {
this.participants = participants;
return this;
}
public CommunicationIdentifier getInitiatorCommunicationIdentifier() {
return this.initiatorCommunicationIdentifier;
}
public ChatMessageContent setInitiatorCommunicationIdentifier(CommunicationIdentifier initiatorCommunicationIdentifier) {
this.initiatorCommunicationIdentifier = initiatorCommunicationIdentifier;
return this;
}
}
Не знаю, как это сделать правильно, потому что при использовании следующего кода я все равно получаю ту же ошибку:
Код: Выделить всё
class CommunicationIdentifierConverter {
private val gson = Gson()
@TypeConverter
fun toCommunicationIdentifier(value: String?): CommunicationIdentifier? {
return value?.let { gson.fromJson(it, CommunicationIdentifier::class.java) }
}
@TypeConverter
fun fromCommunicationIdentifier(identifier: CommunicationIdentifier?): String? {
return identifier?.let { gson.toJson(identifier) }
}
}
Код: Выделить всё
@TypeConverters(
ChatMessageContentConverter::class,
CommunicationIdentifierConverter::class
)
Подробнее здесь: https://stackoverflow.com/questions/784 ... instancecr