Writing serialized objects as XML

What are the advantages and a disadvantages for writing serialized objects as XML instead of the Java binary format?

Depending on the serialization scheme, XML can be used to loosely bind the persistant data, so that the class can change version, or even be replaced by a different class as the project requires refactoring over its lifecycle.
It also allows non-Java tools to interact with your data, which almost always has a longer lifetime than any implementation. I still occasionally process SGML files from the '80s. If they had been in a proprietory binary format, that data would be far harder to re-use.
Pete

Similar Messages

  • Writing JAXRPC Object to XML Stream  by using LiteralObjectSerializerBase

    I am trying to write the JAX-RPC object to a file before I dispatch it to the service provider. What I currently have is :
    QName type = new QName("http://solms.co.za/utils/appsupport", "LicenseRequest");
    XMLWriter writer = XMLWriterFactory.newInstance().createXMLWriter(System.out); 
    LicenseRequest_LiteralSerializer serializer = new LicenseRequest_LiteralSerializer(type, "", AppSupportService_SerializerRegistry.ENCODE_TYPE);
          serializer.initialize(new InternalTypeMappingRegistryImpl(new AppSupportService_SerializerRegistry().getRegistry()));
          serializer.doSerialize(licenseRequest,writer,new SOAPSerializationContext());But it does not work. I have the feeling I am not far off, but still mis something.
    Thanks

    Convert the method signature to a string (such as it is in the class file), and persist that.

  • 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

  • Java.io.StreamCorruptedException: InputStream does not contain a serialized object

              I have an applet which calls a JSP to write data object to the db and then the
              JSP sends back the updated data object. The writing part is ok but the response
              is giving the following error. The data object is in a separate class which implements
              Serialized.
              Here's the code in the applet calling the JSP and the response from the JSP
              URL server = null;
              String urlConnectionString = "http://localhost:7001/isLoginValid.jsp";
              try
              server = new URL(urlConnectionString);
              catch(MalformedURLException e)
              System.out.println("URL exception: " + e );
              // send request
              ObjectInputStream response = null;
              Object result = null;
              try
              URLConnection conn = server.openConnection();
              conn.setDoOutput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("Content-Type", "application/octet-stream");
              ObjectOutputStream request = new ObjectOutputStream(new
              BufferedOutputStream(conn.getOutputStream()));
              request.writeObject((Object)dvo);
              request.flush();
              request.close();
              // get the result input stream
              response = new ObjectInputStream(new BufferedInputStream
              (conn.getInputStream()));
              // read response back from the server
              result = response.readObject();
              if( result!=null && (result instanceof DataVO))
              dvo = (DataVO)result;
              String vo = dvo.printDataVO();
              System.out.println("*DataVO*\n"+vo);
              else
              System.out.println("not an instanceof DataVO");
              catch(IOException ignored)
              System.out.println("Error in DataVO response");
              ignored.printStackTrace();
              Here's the code in the JSP sending the response back to the applet. The 'dvo'
              object is the object which is serialized and has gets and sets for the diff. data
              elements. When I print the 'dvo' before writing the object to outputStream it
              prints the correct values for the data element.
              // send response
              response.setStatus(HttpServletResponse.SC_OK);
              ObjectOutputStream outputStream = new ObjectOutputStream (new BufferedOutputStream
              (response.getOutputStream()));
              outputStream.writeObject(dvo);
              outputStream.flush();
              ERROR is as follows:
              Error in DataVO response
              java.io.StreamCorruptedException: InputStream does not contain a serialized object
              at java/io/ObjectInputStream.readStreamHeader
              at java/io/ObjectInputStream.<init>
              What am I doing wrong?. Please respond soon. The applet is run on IIS and the
              JSP in on weblogic 6.1. I'm not sure if that makes any difference.
              

              I have an applet which calls a JSP to write data object to the db and then the
              JSP sends back the updated data object. The writing part is ok but the response
              is giving the following error. The data object is in a separate class which implements
              Serialized.
              Here's the code in the applet calling the JSP and the response from the JSP
              URL server = null;
              String urlConnectionString = "http://localhost:7001/isLoginValid.jsp";
              try
              server = new URL(urlConnectionString);
              catch(MalformedURLException e)
              System.out.println("URL exception: " + e );
              // send request
              ObjectInputStream response = null;
              Object result = null;
              try
              URLConnection conn = server.openConnection();
              conn.setDoOutput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("Content-Type", "application/octet-stream");
              ObjectOutputStream request = new ObjectOutputStream(new
              BufferedOutputStream(conn.getOutputStream()));
              request.writeObject((Object)dvo);
              request.flush();
              request.close();
              // get the result input stream
              response = new ObjectInputStream(new BufferedInputStream
              (conn.getInputStream()));
              // read response back from the server
              result = response.readObject();
              if( result!=null && (result instanceof DataVO))
              dvo = (DataVO)result;
              String vo = dvo.printDataVO();
              System.out.println("*DataVO*\n"+vo);
              else
              System.out.println("not an instanceof DataVO");
              catch(IOException ignored)
              System.out.println("Error in DataVO response");
              ignored.printStackTrace();
              Here's the code in the JSP sending the response back to the applet. The 'dvo'
              object is the object which is serialized and has gets and sets for the diff. data
              elements. When I print the 'dvo' before writing the object to outputStream it
              prints the correct values for the data element.
              // send response
              response.setStatus(HttpServletResponse.SC_OK);
              ObjectOutputStream outputStream = new ObjectOutputStream (new BufferedOutputStream
              (response.getOutputStream()));
              outputStream.writeObject(dvo);
              outputStream.flush();
              ERROR is as follows:
              Error in DataVO response
              java.io.StreamCorruptedException: InputStream does not contain a serialized object
              at java/io/ObjectInputStream.readStreamHeader
              at java/io/ObjectInputStream.<init>
              What am I doing wrong?. Please respond soon. The applet is run on IIS and the
              JSP in on weblogic 6.1. I'm not sure if that makes any difference.
              

  • How to divide big serialized object in parts to be able to save as Blob typ

    Hi,
    Actually i have serialize a big XML document object and want to save in a field of type Blob. As Blob size is 64k. So if the serialized object is greater than 64k. It gives me error of size.Can anybody tell how to break large serialized objects.
    I am using this code
    File f = new File("out.ser");
    FileInputStream fin = new FileInputStream(f);
    p = farCon.prepareStatement("insert into TeeColor values('3',?)");
    p.setBinaryStream(1, fin, f.length());
    p.executeUpdate();
    This code works fine if the size of out.ser file is less than 64k. But does not work for bigger sizes
    Please help me out
    Thanks

    Read your data from the file into a byte array, then extract 64K at a time into a smaller byte array, and use a ByteArrayInputStream for updating the database.

  • Serializing objects with the NIO API

    I try to use the new IO API to implement a non-blocking multi-threaded server that communicates with client applications by exchanging serialized objects. I started from the code in the JavaWorld article at http://www.javaworld.com/javaworld/jw-09-2001/jw-0907-merlin.html .
    With the new features of J2SDK 1.4.0, you don't have to create a separate thread per connected client. That is a big improvement.
    But when I read an object with ObjectInputStream, I get a java.nio.channels.IllegalBlockingModeException.
    Has anybody successfully implemented such a server since the release of the new io API?
    Thanks.
    Jean-Robert

    The ObjectStream code is basically incompatible with non blockin I/O since you must block on the stream until a whole Object is available. You could roll something like this yourself, by reading bytes until there are enough available to build the next object and then getting that Object from the buffer and shipping it to your client thread. All of this is far more trouble than just using the Stream oriented I/O.
    NIO and mutilple threads are a nightmare, the whole idea of non-blocking I/O is to avoid needing multiple threads. If you do use multiple threads you will need queues between them. See the Taming the NIO Circus topic for lots of discussion of NIO and its problems. The system seems more stable in JDK 1.5, but most people haven't even started using 1.4 for production yet.
    Personally I avoid ObjectStreams. They are only useful between Java applications, if I want that I just use RMI and let Java do ALL the hard work. When I write a Socket based app, its probably because the other end is a mainframe of a C program. For that reason I send data as bytes, packaged up in packets, and encode as XML or ASN.1 so the other end can interpret it.

  • 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.

  • Serialising data objects using XML

    Does the support for XML in wl6.0 mean that java data objects can be serialized using xml entirely within weblogic (currently we use a 3rd party product, and are hoping to remove this if possible)?

    What about SOAP?
    Isn't that what SOAP does - marshals and unmarshals between objects and XML
    You can use SOAP from Java, or C++ or whatever.
    Contrary to a commonly held perception, SOAP doesn't require remote
    transmission of the serialized XML datastream.
    Where is the SOAP support for WLS6 ? I heard it was separately
    downloadable?
    "Alex Thomas" <[email protected]> wrote in message
    news:3a532681$[email protected]..
    >
    With some limitations, yes, if you are starting from a DTD - see the docsfor the WebLogic DTD2Parser tool which generates a high-speed custom parser
    for a given DTD.
    >
    This tool anticipates the JAXB standard (aka Data Binding, formerlyProject Adelard) - see http://java.sun.com/xml/ - which is due fairly
    shortly AFAIK.
    >
    If you were wanting to start with arbitrary Java classes and serializethem to XML you'd have to wait longer unfortunately, though there are some
    implementations around, e.g. http://www.wutka.com/jox.html. This would then
    correspond to marshalling if the objects were parameters to an RPC of some
    kind.
    >
    cheers
    (another) alex
    "alex" <[email protected]> wrote:
    What I should have said is: can wl6 automatically populate java objects
    from xml and vice versa? I believe this is called 'data marshalling and
    unmarshalling', but I cannot find references to this in the doco.
    >>
    >

  • Opening files with serialized objects even if class definition has changed.

    Dear all,
    We are deploying an application wich saves serialized objects. But when changing something in the code and especially in the serialized classes we are not able to open files which have been saved with the old 'outfit' of the class.
    I think, that this is probably a common problem and therefore I am interested whether there exists also a common or practical solution.
    What is the direction I have to look in? XML, Serializable or is it something else?
    Thanks for a short answer,
    Axel

    If you add, remove or change a classes variables, then it will be serialized differently.
    Any fields which you do not need to be serialized, may be marked as transient, so you can add and remove them at will.
    In the longer term, you can override the readObject() / writeObject() methods and explicitely load/save what fields you want. This will also allow you to set intelligent defaults, if for example, you added a new field, but your old serialised classes do not have this field. You can also precede all serialised data with version numbers... might help a bit.
    So code ( psuedocode ) might look like this...
    private void readObject(java.io.ObjectInputStream in)
         throws IOException, ClassNotFoundException;
        int ver = in.readInt();
         classfield1 = in.readLong();
        if ( ver >= 2 )
            classfield2 = in.readLong();
        if ( ver >= 3 )
             classfield3 = in.readLong();
    }regards,
    Owen

  • KVInputFormat corrupting serialized objects

    Hello,
    I am using Oracle NoSQL database for some research project and I have hit an issue I am unsure how to solve. When using the KVInputFormat to pass data from the db into Hadoop the infrastructural corrupts my byte array. As I understand the problem boils down to the infrastructure uses the toString function as per documentation. Unfortunately I am storing serialized object in the db which can contain negative numbers. A String in essence distills down to a char array which only accepts values [0 - 65535] hence all negative number are not handled. Below is a byte array I have retried from the NoSQL database directly and through KVInputFormat
    Original -84 -19 0 5 117 114 0 2 91 74 120 32 4 -75 18 -79 117 -109 2 0 0 120 112
    KVInputFormat: -17 -65 -67 -17 -65 -67 0 5 117 114 0 2 91 74 120 32 4 -17 -65 -67 18 -17 -65 -67 117 -17 -65 -67 2 0 0 120 112
    Is there any solution for this issue (other than writing my own KVInputFormat), or am I just doing something really stupid (its a distinct possibility it has happened in the past).
    Greatly appreciate any assistance
    Alex

    http://java.sun.com/docs/books/tutorial/essential/io/serialization.html
    http://www.churchillobjects.com/c/11009.html
    http://www.acm.org/crossroads/xrds4-2/serial.html

  • Read a field of a serialized object

    Hi,
    is-it possible to read separately a field of a serialized object? By exemple, if I serialize an object that contains a String field, can I read only this String field?
    Thanks
    Jean

    You can do so, if you re-implement Java's serialization spec. That or overload readObject() and wait for your individual field to come in, trap the result and forward it on.
    As you can see from either of these alternatives, there is not a good way to do this. It's like asking 'how can I get an XML fragment from a file?" That task is, on the face of it, far easier. But it equally does not make sense.
    If you have control over the serialization, and you have a key lookup field, serialize it separately in an index-like file or serialize it ahead of Java's serialization in the same file.
    - Saish
    "My karma ran over your dogma." - Anon

  • Serializing objects

    I have two questions:
    1. I am writing a serialized object(SecurityConstraintList) to a socket, everything should be working fine, but I have one problem: the object I am writing has two instance variables that are arrays of SecurityConstraint objects. SecurityConstraint is actually an interface, which is implemented for different constraints.
    So I have:
    SecurityConstraint[] con1 = {a, b, c}
    SecurityConstraint[] con2 = {x, y, z}
    SecurityConstraintList list = new SecurityConstraintList(con1,con2);
    It seems that I can't write the list to the socket unless con1 and con2 are Serializable; but how can I express that the SecurityConstraint interface is Serializable?? I tried to make all the implementing classes Serializable but that doesn't seem to work?
    2. When I want to write serialized objects to a file, with the file being c:\\myProject\file.txt , how can I call the file?
    File file = new File("c:\\myProject\file.txt") doesn't work.
    Thankx

    Who or what is telling you that "system doesn't find the file"?
    "File myFile = new File("c:\\myProject\\file.txt");" doesn't create any physical file. If you call myFile.exists() the result will be "false". (If it hadn't been there before)
    Use "myFile.createNewFile();" and it wil be created.
    If you are using "FileOutputStream fos = new FileOutputStream(myFile);" this should create a file for you. (If it hadn't been there before).
    In this case you get a FileNotFoundException is you dont have the permission to create or open this file.
    So what really happens? I don't know your code.
    By the way: Use slash "/" instead of back slash "\" (The unix style).
    Then there is no need for doubling it. "/" instead of "\\" "//" instead of "\\\\". Java will translate it for you on win systems.

  • AMF3 references - do they reset for each serialized object?

    I have been writing some PHP code to handle AMF3
    serialization and deserialization so that I can pass objects back
    and forth over a socket. In trying to implement the
    AMF3
    specification, I'm having a bit of trouble with the concept of
    references. The
    OSFlash
    site has this to say:
    References are more prominent in AMF3 than in AMF0, and one
    should have two or three arrays to keep track of them, one for
    strings, one for objects and possibly one for class definitions
    (some combine the second and third array). References are
    per-body, so the reference arrays should be reset every time
    a new body is encountered (this can happen if calls are batched or
    if a /onDebugEvents body is sent.
    Does this mean that each time a serialized object is sent
    with a socket.writeObject(someObj) call that I need to reset these
    references and start from scratch? That would make A LOT of sense
    because otherwise, these arrays to track objects would grow QUITE
    large over time.

    You mean the lines below at Timer.java file?
    #if (taskFired) // Task fired; run it, holding no locks
    # task.run();
    That's true; run() method is called synchronously.
    It's a little bit confusing that TimerTask must implement
    the Runnable interface just for this purpose. It let me
    think that's another thread :))
    It could have been another interface which would probably
    be called "TimerContainer" or something like that.
    Anyway, thanks for info.
    java cannot do 'real-time' in any sense of the word.
    As for your question about threading in
    java.util.Timer...
    /me quickly glances at the src code.
    all the Tasks are executed from the same Thread
    synchronously.
    rob,

  • Encrytiong serialized object and seald object

    Hello,
    At the moment I'm writing some code using serialized object stream encrytion. But lately I dicovered sth like sealed objects. My question is what is the difference between creating a SealedObject and then writting it to a stream and encrypting the serialized object as a stream?
    1. What is the purpose for SealedObject regarding the possibility of encrypting serialized objects with streams?
    2. Are there any differences in use of those two ways of securing objects?*
    Thanks for Your replies in advance
    DT

    Read it but not shure wht exactly do U mean. It doesn't ansewer mys questions: of what is the reason for usinf sealedobject where we can encrypt the object with the CipherInputStream (which I have posted as question 1 in the 1st post) and what are the differences in idea of use meaning where should we use CipherInputStream and where Seald object?

  • Error while updating DocumentDefinition AIP-11052:Writing following objects

    Hi All,
    I am getting this error while updating ecs in Document Definition. I was able to do it properly on the same environment a few weeks back but now its throwing an error:
    Error -: AIP-11052: Writing following objects: Document Definition failed due to following constraint violation: DOCUMENTDEFINITION. CAN NOT UPDATE UNVERSIONABLE OBJECT IN A VALIDATED CONFIGURATION
    I read in some of the OTN forums that this may be an environment issue. So i restarted the B2B server as suggested but the error seems to still exist.
    Kindly reply how to proceed. Its little critical.
    Thanks in advance.

    Make sure there is no agreement in deployed/validated state which is using this document definition. Retire and purge all existing configurations which are using this doc def and make sure there is no agreement in validated state. If there is an agreement in validated state and then change/just update anything in agreement and save it to bring it back into draft state.
    Regards,
    Anuj

Maybe you are looking for

  • REP-0004 warning: Unable to open user preferance files

    Hi, I am new to R12. This is the upgradation project 11.5.1.2 to R12. we are newly installed the R12 application and 10g database. I am going to customize the standard report 'Printed Purchase Order Report', the rdf file is 'POXPRPOP'. but it is not

  • Wss3 -- get XML "gibberish" when trying to add new user to site

    Site Actions > Site Settings > People and groups > New Select "book" icon  under Users\Groups, add domain user (works fine). This is displayed in the "Users\Groups" box in Add Users. The text displayed in  "Users/Groups"  looks like this: <span tabin

  • Choose From List Condition

    Dear Experts, i want to select Items in Sales Quotation Screen  which is from Particular Group, I'm using following code If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST And pVal.BeforeAction = True Then             If pVal.FormTye = "

  • Remote-enable bapi to upload employee photos

    hi,all i need to upload emplyee photos from another application system to sap,but i have no idea about such remote-enable bapi. can anybody show me one? Regards Darell

  • I can't get my tabs to open by pressing the tab button

    after getting an update for mozilla firefox, I am now unable to open my tabs via the small tab button on the right side of the open tab. how can I fix this?