micronaut-serialization icon indicating copy to clipboard operation
micronaut-serialization copied to clipboard

Unable to deserialize type [CompletedFileUpload attachment]: No default constructor exists

Open LeylaKhb opened this issue 1 year ago • 6 comments

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

LeylaKhb avatar May 02 '24 22:05 LeylaKhb

CompletedFileUpload is specifically for form data. It is not currently supported for web sockets.

yawkat avatar May 03 '24 06:05 yawkat

@yawkat So how can I get form data from front? I need to get files from

LeylaKhb avatar May 03 '24 11:05 LeylaKhb

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)

LeylaKhb avatar May 06 '24 18:05 LeylaKhb

out of curiosity, how are you sending form data on websockets? ive never heard of this pattern

yawkat avatar May 07 '24 06:05 yawkat

I needed to create chat where people can attach files, so I thought I could do it on websockets

LeylaKhb avatar May 07 '24 08:05 LeylaKhb

I'm wondering what you did on the client side to send form data over websockets

yawkat avatar May 07 '24 11:05 yawkat