Un-serializing java objects.

Hi,
I have a serialized java object.How can I convert it to a normal object or string object?
Thanks
Vivek

Hi,
I am not writing object into a file.I am
just creating a objectoutputstream object.I have to
convert it to string which i guess can be done using
objectInputstream object .So is there any way out?
Thanks
vivekI'm confused by what you are trying to accomplish. An ObjectOutputStream is intended to write objects to a file. You can't convert an ObjectOutputStream to a String, they aren't related. Are you trying to write the objects to a String? I don't see the point of that.

Similar Messages

  • The Proper way to go - Passing Serialized Java Objects vs. Web Services?

    The team which I am apart of in our little "community" is trying to convince some "others" (management) that we should not use web services to communicate (move large data) within the same application (allbeit a huge application spanning across many servers).
    Furthermore these "others" are trying to tell us that in this same application when two small apps. inside of this large app. are both java we should not communicate via serialized java objects but instead we should use Web Services and XML. We are trying to convince them that the simplest way is best.
    They have asked us to provide them with proof that passing serialized java objects back and forth between two smaller java applications inside of a larger one is an Industry Standard. Can anyone help either straighten my fellow workers and I out or help us convince the "others" of the proper way to go?

    When I was a consultant we always gave the client what they wanted. Even if it was the wrong choice. Suck it up.
    I'm glad I wasn't one of those customers. Although I agree that a customer is the one who decides what to do, when I pay someone for consultancy, I expect them to consult me. If they know I'm trying to do something that I shouldn't be doing, I expect a good consultant to be able to show me that there's a better way (not just tell me I'm not doing it right, mind you).
    We pass a lot of data using XML and we don't have any transmission or processing speed issues.
    Then you either have a much better network than our customer did, or we're not talking about the same amounts of data here.
    I used the JAX-RPC RI ...
    That's cool... our customer was, unfortunately, infected with Borland products, so we had to use BES. The web services on BES were run by Axis.
    How large were these messages?
    Huge... each element had about 15 attributes, so 1,200 elements would require 19,200 XML nodes (envelope not included). By comparison, the serialized messages weren't even a quarter that size. It's not just about what you send across the network; it's also the effort of parsing XML compared to desrializing Java objects. Our web service wasn't exactly the only process running at the server.
    Anyone who understand the fundamental difference between ASCII (XML) and binary (serialized) formats realizes that no web service can possibly achieve the performance of binary Java services. Why do you think that work is being put into binary web services? I'm not saying XML is never a good thing; just that it's not The Holy Grail that a lot of people are making it look like.
    http://issues.apache.org/jira/browse/AXIS-688
    Ouch.

  • How to use Java NIO to implement disk cache for serialized java objects

    Hi,
    I have a cache (implemented as hahstable etc.) that contains java objects (mostly strings) and swaps objects from runtime memory to the disk and back based on some algorithms. Currently, the reading and writing from the disk is implemented using java.io.* package i.e. fileInputstream and FileOutputStream. Essentially, I serialize the java object and write to the disk and the deserialize and give it back to the Hashtable cache.
    The performance of swapping from disk to memory is kinda slow. I have read that memory mapping would improve the performance.
    My idea is to do the following:
    Have one big file mapped to memory. I write the serialized objects to different portions of the file and then read those portions when needed. I can use the MappedByteBuffer for that but then I have the following questions. I will not store objects in the hashtable anymore.
    1. How do I delete things from the cache in the above design i.e. how do I delete portions of a mapped file?
    2. How do I serialize objects using ByteBuffers and then deserialize them? I guess this shouldn't be hard but just want to confirm.
    Do you think this is the right design or should I change? Right now using the old io package, I have a separate file for each object. When using the NIO package, I want to store all objects in a single file in different portions of the file, is that the right way to go?
    As you can see, I am beginner in memory mapped io and need help.

    Have one big file mapped to memory. I write the serialized objects to different portions of the file and then read those portions when needed. I can use the MappedByteBufferThis is a good idea, one that I have worked on. It involves quite a bit of manipulation with temporary buffers and a deep working knowledge of object serialization.
    1. How do I delete things from the cache in the above design i.e. how do I delete portions of a mapped file?The best way to handle this is do a two-step process, cutting the file into two pieces and gluing it back together where the original one is...
    2. How do I serialize objects using ByteBuffers and then deserialize them? I guess this shouldn't be hard but just want to confirm.It is hard. Wrapping the streams and making the IO work properly is not the challenge however. The hard part comes in hacking the object streams. The object input/output streams use a ClassDescriptor object which only gets written once/ read once. This shouldn't be a problem if you will read/write the entire file at once, but will bring you grief if you want random access to your objects. You will also need an indexing mechanism to support random access.
    Do you think this is the right design or should I change? Right now using the old io package, I have a separate file for each object. When using the NIO package, I want to store all objects in a single file in different portions of the file, is that the right way to go?I guess it depends on your needs. Do you require random access to objects? NIO provides some performance gains, but mostly for very large amounts of data (>10M in my experience).
    You can always write all your objects into the same file using normal io techniques and you can still generate an index and acheive random access. It might be easier...
    Good luck

  • Serializing Java Objects to XML files

    Hi,
    We looking for SAP library which can serialize Java Objects into XML files.
    Can you point us were to find it ?
    We have found such open source library called "XStream" at the following link
    http://www.xml.com/pub/a/2004/08/18/xstream.html
    Is it allowed to use that library inside SAP released software ?
    Thanks
    Orit

    How about https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/webcontent/uuid/83f6d2fb-0c01-0010-a2ba-a2ec94ba08f4 [original link is broken] [original link is broken]? Depends on your use cases...
    Both are supported in SAP NW CE 7.1.
    HTH!
    -- Vladimir

  • Convert Serialized Java Objects to XML

    I have seen numerous ways that you can modify a java application to serlialize it's data as XML rather than a binary stream. Does anyone know if there are any utilities, libraries, DLLS, tools, whatever to convert an already serialized binary stream to an XML file.
    At the moment I am working on a script to do this, and it works for simple objects, but I am hitting snags as I test with more complicated class heirachies. I would love to find something that already does this for me.

    I want to read data serialized by a java program in a C++ application. I don't want to have to modify the java application, but I do want to make it's data available in other applications.
    I could modify the java app and serialize it's data in XML, but that isn't the prefered solution. :)

  • Can any boby send me a snippet of code telling mw how to "store serialized java object in iplanet directory services

     

    You will find everything you need to know including code samples in the JNDI Tutorial :
    http://java.sun.com/products/jndi/tutorial/objects/index.html
    Regards,
    Ludovic.

  • Sending Custom Java Objects over XML!!

    Hello all !
    Can anybody please tell me how can I send custom Java Objects through XML? For example we can set attributes for a node using the setAttribute method, it accepts only strings, also the setTextContent method requires text and sets the node's value.Can I some way set my own Java object as the value of a particular node or attach it to the node?
    Thanks in advance.

    Kami_Pakistan wrote:
    So I should rather go for Marshalling or Serialization or is there any other work-around possible?I don't know. You didn't say what you had against text formats. Since all Java objects are composed of primitives when you get right down to the bottom, everything in Java can be serialized as text versions of those primitives. So you're going to have to explain why you think a work-around is necessary at all.

  • Comparing java object trees

    Hello.
    I was wondering if someone might have some advice or ideas about this seemingly very common problem.
    I have two copies of a very large java object tree (original and modified). I need to compare these two trees and figure out whether any data has changed. The brute force way to do this would of course be to implement equals() method for all of my objects, but in my case this would be A LOT of work.
    So, I want to find a way to compare the two trees in a generic way.
    My first attempt was to serialize both trees into memory and then compare them on the binary level, like this:
         public boolean autoEquals(BaseDomainObject other) {
              try {
                   ByteArrayOutputStream thisObjectStream = new ByteArrayOutputStream(500);
                   ObjectOutputStream out = new ObjectOutputStream(thisObjectStream);
                   out.writeObject(this);
                   out.flush();
                   out.close();
                   ByteArrayOutputStream otherObjectStream = new ByteArrayOutputStream(500);
                   out = new ObjectOutputStream(otherObjectStream);
                   out.writeObject(other);
                   out.flush();
                   out.close();
                   return thisObjectStream.toString().equals(otherObjectStream.toString());
              catch (Exception e) {
                   throw new RuntimeException(e);
         }This actually nearly worked, except for one problem that I do not know how to address - The order of elements in collections of the modified tree might differ from the order of the same collections in the original tree, even if the individual elements are exactly the same. My serialization idea falls apart here.
    Can someone think of another way to do this?
    Any ideas would be appreciated.

    I thought I would follow up with the solution.
    The method I described above does work, but in order to make it work I had to find a way to make all elements in all collections appear in the same order. In order to do that, I needed a unique key for each object in the tree, that would be the same in both the original and the modified tree.
    In my case that was easy, b/c I get the original version from Hibernate and I make my modified version by copying it (also by serializing the original into memory and then deserializing it into my new "modified" working copy tree), so they both still contain the hibernate oids.
    The extra step I needed to do before serializing and comparing was to recurse through both trees (with Introspection) and replace all sets with a TreeSet and all lists with my own implementation of a sorted list.
    Now I can compare any tree of domain objects that extend from BaseDomainObject (they all do) by simply writing
    domainObjectTree1.autoEquals(domainObjectTree2, new String[] {"terminatorProperty1", "terminatorProperty2", ...})
    Terminator properties are basically properties which I set to null before running my comparison. This allows me to "cut off" branches of the tree that I don't want to be compared.

  • Setting workflow payload as Java object

    Hello,
    The documentation for CQ workflows indicates that a Java object can be passed as the payload data for a workflow process.  I have a Java class that implements the WorkflowProcess interface and have hooked it up so I can invoke it programmatically.
    However the documentation does not give any insight on the "payload type" options other than "JCR_PATH".  If I use JCR_PATH then it expects the Object passed to be a string (a node path obviously).  Passing anything else will cause a class cast exception. Using any payload type other than JCR_PATH results in the log message "com.day.cq.workflow.impl.jcr.WorkflowManager No payload set" and the process does not get invoked correctly.  They show up in the Workflow instances UI as RUNNING and have no payload (basically stuck).
    Any help?

    That's a reasonable limitation of the implementation behind the interface. Just serialize your payload into a JCR node (or a node structure) and then add this node as payload to the workflow. The WF steps then process this node.
    A possible explanation for this: A workflow is guaranteed to be executed exactly once. So at the end of every workflow step the payload must be serialized to the repository to ensure that the next step can be repeated if it fails for any reason. So you can either serialize it yourself and upfront (the workflow then just updates this node struecture) or you would need some OR mapper here, which does this job for you. I prefer the first approach :-)
    kind regards,
    Jörg

  • Serializing & Deserializing objects through ObjectMessage

    Hi,
    I'm having trouble sending objects/instances of a class (Data) through the message queue. I also made Data to be serializable.
    public class Data implements Serializable {
    }The following are snippets of code from the Message producer side:
    objectMessage = mySess.createObjectMessage();
    MessageProducer myMsgProducer = mySess.createProducer(myQueue);
    Data e = new Data();
    objectMessage.setObject(e);
    myMsgProducer.send(objectMessage);And the following are snippets of code from the message consumer:
    public void onMessage(Message message) {
                 if(message instanceof ObjectMessage ){
             try{
                  ObjectMessage objMsg = (ObjectMessage) message;
                  Data myData = (Data)objMsg.getObject();
             catch(JMSException e){
                  System.out.println("Exception occured: " + e.toString());
    }The result of attempting to cast the objMsg to a Data is an exception thrown.
    i did noticed however, that when I was debugging the message consumer, that the byteArrayInputStream values for both message and objMsg are null meaning that the data is not being sent or received. Any help would be greatly appreciated, thanks!
    Edited by: 883631 on Sep 13, 2011 4:09 PM
    Edited by: EJP on 14/09/2011 09:22: added {noformat}{noformat} tags. Please use them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Sorry, the exception thrown is:
    Exception occured: com.sun.messaging.jms.MessageFormatException: [C4015]: Deserialize message failed. - cause: java.lang.ClassNotFoundException: MsgSender.Data
    Sep 14, 2011 8:53:50 AM com.sun.messaging.jmq.jmsclient.ExceptionHandler logCaughtException
    WARNING: [I500]: Caught JVM Exception: java.lang.ClassNotFoundException: MsgSender.Data
    where MsgSender is the name of the project that produces the messages to the queue.
    Data is the class that is both on the sender and receiver side, and the exception is thrown as a result of casting the object message back into a type Data.
    Data myData = (Data)objMsg.getObject();
    I hope this isn't too confusing. What I'm wondering is if there are extra steps to serializing your object or if the ObjectMessage's setObject method automatically does that for you so as long as you declare your class to implement Serializable. And if that's the case, how do you deserialize it back to the original object?
    Thank you

  • Saving java objects without serialization

    Hi!
    I want to save a lot of java objects to file, and be able to restore the data structure that these java objects compose.
    The obvious way to do that, is to use some kind of serialization I guess. But, as I see it, the problem with this approach is that as the data structure expands and new classes are added and present classes are changed (even the name of the classes) this approach fails. If the user has an old data structure that he/she wants to restore there will be a problem with e.g. ClassCastException and the like.
    Now I am wondering if someone could give me some hints of how to solve this problem. What approach should I use instead. Is XML the right way to do it? Someone who has any experience with these problems?
    I would really appreciate some help!
    Best regards
    Lars

    Hi, Lars, funny you should mention this issue. I am
    dealing with the exact same problem at work. Every
    time I release a new version of my software, users
    cannot load files they saved with the previous
    version. This is a big problem !
    And, like you, I am toying with the XML solution.
    On the downside, saving these objects in an XML format
    will take more memory, as XML can be (and should be?)
    textually descriptive. Those ASCII tags and such will
    probably treble the file size of their streamlined
    "serialized" predecessors.
    But memory is cheap, eh ?
    On the plus side, your XML parser can be (by it's nature)
    forgiving if new fields have been added or old ones taken
    away. And that is why Serializable is giving be a headache
    to begin with !
    Two other thoughts cross my mind ...
    For exceedingly large files, a SAX parser (vice DOM) will
    only have a bit 'o the structure in memory at a time, instead
    of having the whole kit and kaboodle in memory (my understanding
    of DOM).
    Also, nothing is stopping me from taking a gander at some of
    the Zip packages ... now where did I run across them ? java.io ? ...
    where once I write out the XML file (saving my objects), I could
    compress 'em for the user, too :-) I seem to recall a ZipStream or
    something while scanning some of the (JDK 1.4?) packages.
    I am looking forward to your response, and those of other interested
    readers sharing their thoughts on this topic, too !
    Eric

  • Serializing Java Boolean to AS

    Hi. I have a weirdest problem - my Boolean field are not deserialized property to AS Boolean variables. Namely it is always null fo rme. Simple Java boolean works fine, but not Boolean. I am not sure what to do. I was able to go around it until I had to return Map<String, Boolean> from my method. Any ideas, hints? It is more or less simple as that:
    JAVA:
    class A {
        private Boolean _Foo = Boolean.TRUE;
        private Map<String, Boolean> _Flags;
        public Boolean getFoo() { return _Foo; }
        public Map<String, Boolean> getFlags() { return _Flags; }
    AS:
    class A {
        private var foo:Boolean;
        private var flags:Object;

    There is no single way to serialize Objects to a stream so I'm not really sure what kind of answer you are expecting. I'm not sure that all serilizable Java Objects are serializable to XML in a generic way.
    Value types i.e. beans are pretty easily serialized and deserialized to XML, but the class definition of what you serialize may not be whatr you get when you deserialize the XML.

  • Generation of XML file from Java objects using castor

    I have the following java file(Customer.java).
    public class Customer
         private String ID;
         private FirstName firstName;
         private MiddleName middleName;
         private LastName lastName;
         private ArrayList address;
         public ArrayList getAddress() {
              return address;
         public void setAddress(ArrayList address) {
              this.address = address;
         public FirstName getFirstName() {
              return firstName;
         public void setFirstName(FirstName firstName) {
              this.firstName = firstName;
         public String getID() {
              return ID;
         public void setID(String id) {
              ID = id;
         public LastName getLastName() {
              return lastName;
         public void setLastName(LastName lastName) {
              this.lastName = lastName;
         public MiddleName getMiddleName() {
              return middleName;
         public void setMiddleName(MiddleName middleName) {
              this.middleName = middleName;
    Using castor i have created an xml file(customer.xml) which has the following format.
    <?xml version="1.0" encoding="UTF-8" ?>
    - <customer ID="fbs0001">
    <FIRSTNAME>Fred</FIRSTNAME>
    <MIDDLENAME>B</MIDDLENAME>
    <LASTNAME>Scerbo</LASTNAME>
    - <ADDRESS>
    <FIRSTLINE>No 18, Sheshadri road</FIRSTLINE>
    <SECONDLINE>Gandhinagar Bangalore</SECONDLINE>
    </ADDRESS>
    - <ADDRESS>
    <FIRSTLINE>ITPL</FIRSTLINE>
    <SECONDLINE>Whitefield Bangalore</SECONDLINE>
    </ADDRESS>
    </customer>
    I have used a mapping file to get this output.Is there a way where i can get the output xml in the following format without changing the Java object structure.If yes then please suggest how this can be done.
    <?xml version="1.0" encoding="UTF-8" ?>
    - <customer ID="fbs0001">
    <FIRSTNAME>Fred</FIRSTNAME>
    <MIDDLENAME>B</MIDDLENAME>
    <LASTNAME>Scerbo</LASTNAME>
    </customer>
    <ADDRESS>
    <FIRSTLINE>No 18, Sheshadri road</FIRSTLINE>
    <SECONDLINE>Gandhinagar Bangalore</SECONDLINE>
    </ADDRESS>
    - <ADDRESS>
    <FIRSTLINE>ITPL</FIRSTLINE>
    <SECONDLINE>Whitefield Bangalore</SECONDLINE>
    </ADDRESS>
    I mean the output xml file should have the address as a separate tag not withing the root tag customer.

    Hello,
    Castor's own discussion groups might be able to point you to the solution you're looking for (if this use case is possible using Castor).
    Oracle has its own object-to-XML mapping tool that is part of the TopLink product. It allows you to map existing objects to an existing XML Schema. This can be done visually using the TopLink Workbench, or programmatically using the TopLink APIs. TopLink OXM also supports the JAXB specification.
    Using TopLink OXM to get the desired XML result I would recommend the following. Map the Customer and Address classes to XML, but don't map the relationship between Customer and Address. Then make the calls to the marshaller something like the following:
    marshaller.marshal(aCustomer, System.out);
    for(int x=0; x<aCustomer.getAddress().size(); x++) {
         marshal(aCustomer.getAddress().get(x), System.out);
    Example - Using TopLink OXM to map an existing object model to an existing XML Schema:
    http://www.oracle.com/technology/products/ias/toplink/preview/10.1.3dp4/howto/ox/index.htm
    For more information on TopLink object-to-XML mapping:
    http://www.oracle.com/technology/products/ias/toplink/preview/10.1.3dp4/objectxml/index.html
    -Blaise

  • Empty strings when passing a Java object to a Stored Procedure

    Hi,
    I'm using the interface SQLData to pass Java objects to StoredProcedures. All the object's attributes 'arrive' to the Stored Procedure ok, except the strings, which are empty.
    Here is my Oracle object:
    TYPE OBJ_ASJFF_OBJ1 IS OBJECT (
    ARG1 CHAR(3),
    ARG2 NUMBER(4),
    ARG3 CHAR(4),
    ARG4 NUMBER(7),
    ARG5 NUMBER(13,2),
    ARG6 CHAR(1));
    The nested table of that object:
    TYPE TAB_ASJFF_OBJ1 AS TABLE OF OBJ_ASJFF_OBJ1;
    The procedure declaration:
    PROCEDURE Pup_Instaura_Processo (                              x_crCert IN TAB_ASJFF_OBJ1,
    x_cResult OUT CHAR(4)
    My SQLData implementation:
    public void writeSQL(SQLOutput stream) throws SQLException {
                   stream.writeString(getArg1());     
                   stream.writeInt(getArg2().intValue());
                   stream.writeString(getArg3());          
                   stream.writeLong(getArg4().longValue());     
                   stream.writeBigDecimal(getArg5());
                   stream.writeString(getArg6());
    Can anybody help me?
    Thanks in advance
    Rui Gonçalves

    not exactly what you wanted but ingredients can be found at
    - JPublisher's docuemntation (especially "Type Mapping Support Through PL/SQL Conversion Functions")
    - http://otn.oracle.com/sample_code/tech/java/jsp/Oracle9iJSPSamples.html (Best Hotels PL/SQL Sample )
    - http://otn.oracle.com/tech/xml/xdk_sample/xdksample_093001i.html
    hope this helps
    Kuassi
    I have a Java Stored procedure which takes an instance of a different java object as its parameter.
    I need to do this from a pl/sql package - can anyone point me to a sample etc (looked on the website but don't see one) ?
    Andrew

  • Problem with XMLEncoder for complex java object i

    Hi All.
    My problem with XMLEncoder is it doesnt transfrom java objects without default no arguement constructor. I was able to resolve this in my main java object class, by setting a new persistence delegate, but for other classes that are contained in the main class, they are not being encoded.
    Thanks in advance for your answers

    Better to put this in java forum :-)
    Just check, if this helps.
    http://forum.java.sun.com/thread.jspa?threadID=379614&messageID=1623434

Maybe you are looking for