Results 1 to 5 of 5
- 01-09-2009, 04:58 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 9
- Rep Power
- 0
Serializing an object not working properly - funky chars.
I have a java webservice.. I need to log the response before returning. I am trying to serialize as below:
ByteArrayOutputStream fos = new ByteArrayOutputStream();
ObjectOutputStream outStream = new ObjectOutputStream( fos );
outStream.writeObject( response );
outStream.flush();
return fos.toString();
But I see invalid characters all over. What is the process of saving it as proper xml text content? This object is Serializable and complex data type.
Thanks,
- 01-09-2009, 07:11 PM #2
Serialization creates binary output, some of which may be legible, such as the contents of String. It is not intended to be human readable.
You can use XMLEncoder on any object that follows the Java Beans conventions, but it will only save public properties (fields with public getXxx, isXxx, setXxx methods).
If you want to save the response and read it back as as Java object, user serialization. If you want a human-readable archive, use XMLEncoder.
- 01-09-2009, 07:21 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 9
- Rep Power
- 0
any example to convert from object to string(XML) using XMLEncoder?
- 01-09-2009, 08:04 PM #4
Member
- Join Date
- Jan 2009
- Posts
- 9
- Rep Power
- 0
It works fine when I changed to XMLEncoder
ByteArrayOutputStream fos = new ByteArrayOutputStream();
try {
XMLEncoder encoder = new XMLEncoder(fos);
encoder.writeObject(response);
encoder.flush();
return fos.toString();
}
Thanks,
- 01-10-2009, 12:17 AM #5
Similar Threads
-
event handler not working properly
By H3rtaherta in forum Java 2DReplies: 3Last Post: 11-24-2008, 02:39 AM -
Object not serializing
By MamboBanda in forum New To JavaReplies: 1Last Post: 08-12-2008, 12:15 AM -
My code is not working properly ..modify it
By Shyam Singh in forum New To JavaReplies: 14Last Post: 07-16-2008, 05:48 PM -
Log4j not working properly....
By prakash_dev in forum Advanced JavaReplies: 0Last Post: 03-17-2008, 12:13 PM -
How do I omit an object when serializing?
By Hasan in forum Advanced JavaReplies: 1Last Post: 05-31-2007, 04:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks