Explain "did conversion".
And what is the "object", and why does the other method expect a byte?
What does the other method do?
In an case, you can only serialize the object, i.e. wrap a bytearrayoutputstream in a objectoutputstream and write the object to it. Not that I can even begin to imagine how this would benefit anything.
ok, and how do you think that Object you get from "val" is going to match the content expected in that byte array?
Most likely it expects some sort of mapping of a String to a byte, converting the multibyte characters of Java to single byte characters, probably by stripping anything that's not ASCII.
If the Object represents a String, that's not too hard to do. If it doesn't, god only knows what steps you'd have to take as it would depend entirely on the data structure of that object.
I stored one object in session and, have to pass into another method which expects byte.
How to do this conversion?
What is this line of code doing?
Object obj = session.getAttribute("val");
If the underlying datatype 'getAttribute' is returning is a String then just cast 'obj' to a String and use the 'getBytes' method to get a byte array
byte attributeArray = ((String) obj).getBytes();
See the String Java API