Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LeylaKhb opened this issue May 2, 2024 · 6 comments

Comments

@LeylaKhb
Copy link

LeylaKhb commented May 2, 2024

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

@yawkat
Copy link
Member

yawkat commented May 3, 2024

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

@LeylaKhb
Copy link
Author

LeylaKhb commented May 3, 2024

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

@LeylaKhb
Copy link
Author

LeylaKhb commented May 6, 2024

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)

@yawkat
Copy link
Member

yawkat commented May 7, 2024

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

@LeylaKhb
Copy link
Author

LeylaKhb commented May 7, 2024

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

@yawkat
Copy link
Member

yawkat commented May 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: No status
Development

No branches or pull requests

2 participants