Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

Ask questions and see you at April, 6th, 6.PM. CET:

Also checkout recent episode:


Please keep the questions Java EE-stic. Means: as short and as concise as only possible. Feel free to ask several, shorter questions.


This comment has been minimized.

Copy link

nkengasongatem commented Mar 16, 2019

Hi Adam, I am working on project which uses JS at the frontend and Jakarta EE at the backend. I would like to persist submitted form data containing a picture, and save this picture as blob (despite the shortcomings) in a MySQL database. I tried the method below but JSONB fails during deserialization of the 'candidatePicture' field.

 var file = URL.createObjectURL(document.getElementById("candidatePicture").files[0]);
         fetch(file).then(response => {
            response.blob().then(photo => {

             const reader = new FileReader();

            // Start reading the blob as text.
            // This fires after the blob has been read/loaded.
            reader.addEventListener('loadend', (e) => {
                const text = e.srcElement.result;
                var ballotData = $("#addBallotForm").serializeArray();
                var ballot = {
                    "candidateName": ballotData[0].value,
                    "positionName": ballotData[1].value,
                    "candidateNIC": ballotData[2].value,
                    "partyname": ballotData[3].value,
                    "candidateSlogan": ballotData[4].value,
                    "candidatePicture": text,
                    "actionPlan": ""

                    headers: {
                        'Content-Type': 'application/json'
                    crossDomain: true,
                    type: "POST",
                    enctype: 'application/json',
                    processData: false, // Important! prevent jQuery from transforming the data into a query string 
                    cache: false,
                    url: url,
                    data: JSON.stringify(ballot)
                }).done((data, textStatus, jqXHR) => {
                    if (jqXHR.status === 200) {
                        swal("The ballot has been succesfully created!", {icon: "success"})
                                .then((confirm) => {
                                    if (confirm) {
                                        clearAddBallotModal(); // clear the form
                                        $("#addBallotModal").click(); // close the modal
                                        displayBallots(); // redisplay the ballots
                    } else {
                        swal("Oops! Invalid ballot Input", {icon: "warning"});
                }).fail((jqXHR, textStatus, errorThrown) => {
                    swal("Error! An error occured!", {icon: "error"});



In my netbeans 8.2 console i get:
Severe: Error deserializing object from entity stream. Error deserializing object from entity stream.

This is my resource endpoint method:

    @ApiOperation(value = "Create new ballot item", notes = "This can only be done by logged in users.")
    @ApiResponses(value = {
    @ApiResponse(code = 400, message = "Invalid ballot item Input"),
    @ApiResponse(code = 200, message = "Ballot item created")})
    public Response add(
        @ApiParam(value = "The ipaddress of the ballot item to be created", required = true) @PathParam("ipaddress") String ip,
        @ApiParam(value = "The election's id", required = true) @PathParam("electionid") String electionid,
        @ApiParam(value = "The ballot item that needs to be added", required = true) BallotItem newBallot) {

    Election election = electionService.find(Long.parseLong(electionid));
    return Response.ok(newBallot).build();

Please how can i get this to work? Thanks in advance


This comment has been minimized.

Copy link
Owner Author

AdamBien commented Mar 20, 2019

Thoughts on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.