1

I am getting some input from the user on client side with no limit on characters. So I am storing input as a BLOB data type.

I am directly getting my entity filled using getters and setters.

Action class:

public class OperatorNotesAction extends ActionSupport {
    

    private static final long serialVersionUID = 1L;
    
    private OperatorNotesInfo note;
....    
}

OperatorNotesInfo is the entity I wana get filled. On client side I send the input filled by the user to the action class using JavaScript:

JS:

$.ajax({
    type: 'POST',
    url: "<s:url action='updateNote'/>",
    data:
    {                   
        'note.title':$('#title').val(),
        'note.id.operatorId':$('#operatorId').val(),
        'note.content':$('textarea').val()

    },

Here content is of byte array type in action class as it's stored as a BLOB.

How do I type convert the input entered by the user into byte array, so that content property of the entity note gets saved ?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Siddharth Trikha
  • 2,648
  • 8
  • 57
  • 101

1 Answers1

0

You need to write a custom type converter. Strings from input are converted as String type by default. You can read which types conversion is supported via built-in type conversion. If you want to convert a string to bytearray you need to write a converter. Then use it with your property

@TypeConversion(converter="org.conversion.StringToBytearrayConverter")
public void setContent(byte[] bytes) {
  this.content = bytes;
}
Community
  • 1
  • 1
Roman C
  • 49,761
  • 33
  • 66
  • 176