micronaut-serialization
micronaut-serialization copied to clipboard
Unable to deserialize type [CompletedFileUpload attachment]: No default constructor exists
Expected Behavior
I want to get messageDto from frontend in my websocket
@OnMessage
fun onMessage(message: MessageParamsDto,
session: WebSocketSession) {
println(message)
}
MessageParamsDto:
@Introspected
@Serdeable
class MessageParamsDto {
var textContext: String
var attachment: CompletedFileUpload? = null
constructor(textContext: String, attachment: CompletedFileUpload) {
this.textContext = textContext
this.attachment = attachment
}
}
Actual Behaviour
I get error
io.micronaut.http.codec.CodecException: Error decoding stream for type [class com.example.message.dto.MessageParamsDto]: Unable to deserialize type [CompletedFileUpload attachment]: No default constructor exists
Steps To Reproduce
No response
Environment Information
No response
Example Application
No response
Version
4.3.6
CompletedFileUpload is specifically for form data. It is not currently supported for web sockets.
@yawkat So how can I get form data from front? I need to get files from
So for everyone who meets the task of saving files in websocket, I didn't find any other solution except posting to controller with CompletedFileUpload and returning id of created message and then adding text to this message in websocket (or creating new message without files in websocket)
out of curiosity, how are you sending form data on websockets? ive never heard of this pattern
I needed to create chat where people can attach files, so I thought I could do it on websockets
I'm wondering what you did on the client side to send form data over websockets