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

Similar Messages

  • Process.start("winword", filename) can not open file with space in the path and name

    Hi,
    I am trying to write a class which can open file with selected application. for simplicity, now I just hard code the varaibles.
    the problem: if the path or file name has space in it, even it exist, winword still can not open it.
    could someone kindly show me what I did wrong and how to do it properly.
    Thanks in advance.
    Belinda
    public static class FileOpen
    public static void info()
    string path = @"c:\a temp folder\aaa 1.txt";
    if (File.Exists(path))
        // the file I am using in the sample does exist
         MsgBox.info("yes");
    else
         MsgBox.info("no");
    // working
    //Process.Start("winword", "c:\\aaa.txt");
    // not working
    //Process.Start("winword", "c:\aaa.txt");
    // not working
    Process.Start("winword", "c:\\a temp folder\\aaa 1.txt");
    // not working
    Process.Start("winword", path);

    string AppPath;
    AppPath = ReadRegistry(Registry.CurrentUser, "Software\\FabricStudio", "TARGETDIR", value).ToString() + @"help";
    string FileName = "'"+ AppPath + "\\ImageSamples.doc" + "'";
    try
    System.Diagnostics.Process.Start("Winword.exe", FileName);
    can any body please help for this.
    where i am making mistake?

  • [Flex mobile] Open file with a Filebrowser

    Hi everyone,
    i want to be able to open files with a file browser in my app, but the browse dialog which is opened by the File.browse() method only displays / opens music or image files. Furthermore im not even able to change the Dialog header when running my project on android:
    dir.browseForOpen("Please select a file");
    this doesn't work on android, neither does the next code-block:...
    var dir:File=new File(File.userDirectory.url+ "/geoforms");
    var filter:FileFilter=new FileFilter("Documents","*.txt");
    dir.browseForOpen("Please select a file",[filter]);
    So what do i have to do, to be able to show a decent file select dialog ?

    Nobody any idea?
    i tried it like its described in this article:
    Declaring file type associations
    http://livedocs.adobe.com/flex/3/html/help.html?content=File_formats_1.html
    but i can't get it running for my mobile project. The  type associations works fine in my desktop air application but it doesn't work in my mobile app. Is this  type associations stuff supposed to be working on mobile devices / android?

  • Open file with reference

    Hi
    I want to open files with a reference in hidden mode. Is this possible?
    Because I want to make a program where the user can choose a new test station and then the controls and indicators will be created (or become visible) and the subroutine begins to run.
    Does anybody have a good idea or even an example how to do this?
    Best regards,
    Yves

    Hi Yves,
    You could control your Test- VI with a global variable as shown below. This solution uses two independent while- loops. The Test-VI won't be opened and does the work invisible.
    This is the Main-VI
    And this is the Test-VI
    Greets, Dave
    Message Edited by daveTW on 09-28-2006 03:30 PM
    Greets, Dave
    Attachments:
    Test VI.png ‏2 KB
    Control VI.llb ‏31 KB
    Main VI.png ‏7 KB

  • Opening files with servlet

    Okay... I'm new to using servlets. Not so much to jsp, just to using servlets. I have one process on our site that is using servlets and I'm trying to mimic how that is using em but am having no luck.
    I am trying to open files with a servlet. I have the class built and compiled, but mainly pulled it from Java World. I evenually will need to pass the servlet the filename and path I want open but in this example it has the file set. My problem is I want to send users to a jsp file where I check user authentication and call the servlet to open the doc, but I don't know how to call the servelet or what to send it. If someone could maybe walk me through this.
    Here's my servlet:
    package cmxx.fileServe;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class fileServe extends HttpServlet {
    final static String CONTENT_TYPE_DOC = "application/msword";
    final static String CONTENT_TYPE_HTML = "text/html";
    final static String document = "/docs/form_41.doc";
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    doGet(request, response);
    public void doGet (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    PrintWriter out;
    out = response.getWriter();
    HttpSession websession = request.getSession(true);
    response.reset();
    response.setDateHeader ("Expires", 0);
    response.setDateHeader("max-age", 0);
    try {
         response.setContentType(CONTENT_TYPE_DOC);
    FileInputStream fileInputStream = new FileInputStream(document);
    ServletOutputStream servletOutputStream = response.getOutputStream();
    int bytesRead = 0;
    byte byteArray[] = new byte[4096];
    while((bytesRead = fileInputStream.read(byteArray)) != -1) {
         servletOutputStream.write(byteArray, 0, bytesRead);
    servletOutputStream.flush();
    servletOutputStream.close();
    fileInputStream.close();
    } catch(Exception ex) {
         throw new ServletException(ex.getMessage());
    } /* end doget */
    } /* end class */

    I'm trying a new servlet. But am getting a few compile errors. Can someone help?
    Here are my Errors:
    43 cannot resolve symbol
    symbol : class URL
    location: class cmis.fileServe.fileServe2
    URL url = new URL(fileURL);
    ^
    43 cannot resolve symbol
    symbol : class URL
    location: class cmis.fileServe.fileServe2
    URL url = new URL(fileURL);
    ^
    57 cannot resolve symbol
    symbol : class MalformedURLException
    location: class cmis.fileServe.fileServe2
    } catch(final MalformedURLException e) { 
    ^
    Code:
    package cmis.fileServe;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class fileServe2 extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    ServletOutputStream out = res.getOutputStream();
    // Set the output data's mime type
    res.setContentType( "application/pdf" ); // MIME type for pdf doc
    // create an input stream from fileURL
    String fileURL = "http://www.adobe.com/aboutadobe/careeropp/pdfs/adobeapp.pdf";
    // Content-disposition header - don't open in browser and
    // set the "Save As..." filename.
    // *There is reportedly a bug in IE4.0 which  ignores this...
    res.setHeader("Content-disposition", "attachment; filename=Example.pdf" );
    // PROXY_HOST and PROXY_PORT should be your proxy host and port
    // that will let you go through the firewall without authentication.
    // Otherwise set the system properties and use URLConnection.getInputStream().
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    try {
    URL url = new URL(fileURL);
    // Use Buffered Stream for reading/writing.
    bis = new BufferedInputStream(url.openStream());
    bos = new BufferedOutputStream(out);
    byte[] buff = new byte[2048];
    int bytesRead;
    // Simple read/write loop.
    while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
    bos.write(buff, 0, bytesRead);
    } catch(final MalformedURLException e) {
    System.out.println ( "MalformedURLException." );
    throw e;
    } catch(final IOException e) {
    System.out.println ( "IOException." );
    throw e;
    } finally {
    if (bis != null)
    bis.close();
    if (bos != null)
    bos.close();
    } /* end class */

  • [SOLVED] Sudo Ranger does not open files with VIM

    I am using ranger as my file manager. And sometimes I run it with sudo. But then it want's to open all with nano. Even tough the environment variables (EDITOR & VISUAL) are set to vim.
    Maybe it hast something to do with /bin/sh - but when that is the case, how do I change the default behaviour of /bin/sh?
    Last edited by natepad (2015-04-02 16:07:36)

    Sure you can. As the sudoers man page describes, the env_reset option is on by default. You could use the env_keep options. Or use the -E flag for sudo. Or....
    http://www.sudo.ws/sudo/man/1.8.13/sudo.man.html
    http://www.sudo.ws/sudo/man/1.8.13/sudoers.man.html

  • Snow Leopard 10.6.2 CS4 InDesign can't open files with a "#" in file path

    Snow Leopard 10.6.2 CS4 InDesign can't open files with a "#" in file path using any of these perfectly normal methods:
    1. double-click file in the Finder (e.g in a Folder on your Mac or on your Mac desktop etc.)
    2. select file and choose "File... Open" command-o in the Finder
    3. drag file to the application icon in the Finder.
    4. Select file in Bridge and double-click, choose File.. Open.. or Drag icon to InDesign icon in dock.
    If you try to open an ID file named with a "#", you will get an error message "Missing required parameter 'from' for event 'open.'"
    This happens to any InDesign file that has a "#" (pound sign, number sign, or hash) in the filename or in the file path (any parent folder).
    To reproduce
    Name an InDesign file Test#.idd Try to open it in the Finder or Bridge (as opposed to the "Open" dilaog of InDeisng itself).
    "Solution"
    The file WILL open using File... Open... command-o while in InDesign application.
    Rename the file or folders that have a "#" (shift-3) in the filename.
    Report to Adobe if it bugs you.
    This does not occur in "plain" Leopard 10.5 nor Tiger 10.4
    Untested in Panther or before and
    Untested with CS3 and earlier in Snow Leaopard.
    Anyone have those and want to try this... ?

    In case this really bothers you: we've added a workaround for this into Soxy. If you enable the option, these documents will open fine on double-click.
    You need Soxy 1.0.7 from:
    http://www.rorohiko.com/soxy
    Go to the 'Soxy' - 'Preferences' - 'Other' dialog window, and enable 'Open InDesign via Script'
    (Irrelevant background info (it's all invisible to the user): the workaround works by special-casing how Soxy opens documents in InDesign: instead of using AppleScript, Soxy will use ExtendScript to instruct InDesign to open the document - which works fine).

  • Opening files with Illustrator and photoshop doesn't work, i have to drag the files from finder in to the program. This problem appears after opening 4 a 5 files.

    Opening files with Illustrator and photoshop doesn't work, i have to drag the files from finder in to the program.
    This problem appears after opening 4 a 5 files, rebooting helps another 4 a 5 times and appears again.

    I'd recommend reposting in the Boot Camp forum, that is where the Boot Camp and Windows gurus hang out.
    Good luck.

  • Adobe Bridge CC crashes when opening file with Photoshop CC or Camera RAW!

    Adobe Bridge CC crashes when opening file with Photoshop CC or Camera RAW!
    - Tried to Reset the preference with CTRL + Click.
    - It's just new clean install didn't do anything with it yet.
    - Windows 8.
    Any help?

    Just that one project, or any project?  Can you create new projects?

  • Cannot open PDF files with Reader XI message appears Adobe Reader has stopped working

    Cannot open PDF files with Reader XI message appears Adobe Reader has stopped working. A problem has caused the program to stop working

    Which Operating system you are using?
    Can you open Adobe Reader by itself?  If so, try disabling Protected Mode [Edit | Preferences | Security (Enhanced)] and then try to open the file.

  • Photoshop CS6 (Mac) crashes when opening files with type or using the type tool

    Hi,
    Photoshop CS6 keeps crashing when using the type tool or when opening files with type on it. I've quit suitcase, disabled the suitcase plug-in, reset the preferences in Photoshop there's no crash report coming up either the application just dies! I am currently trying a system restore from time machine to see if that works!. Any other suggestions would be greatly appreciated.
    Many thanks
    Olly

    http://blogs.adobe.com/crawlspace/2012/07/photoshop-basic-troubleshooting-steps-to-fix-mos t-issues.html
    http://helpx.adobe.com/photoshop/kb/troubleshoot-fonts-photoshop-cs5.html

  • Can´t open files with camera raw

    Hi!
    I use Adobe Photoshop CS3 and the option to open files with Camera Raw is disabled in Bridge and in PS.
    Can anyone help?

    While each situation can be different this has been discussed on several threads. Scan down the list or do a search. If you can't find the answer, post a note.

  • Indesign opens files with no space between each word, this happened after a mac update, help?? I don't want to have to go through and manually do it.

    indesign opens files with no space between each word, this happened after a mac update, help?? I don't want to have to go through and manually do it.
    thanks in advance!

    If you are unable to enter the passcode into your device, you will have to restore the device to circumvent that passcode.
    Is the music purchased from iTunes? If it is you can contact iTunes support and ask them to allow you to re-download the music that you purchased from iTunes.
    Also, do you sync the device regularly? When syncing an iPod Touch/iPhone a backup file is made. That backup file doesn't contain your music but it does contain your address book, application data, pictures, notes, etc. After restoring your device, you can try restoring from the last backup that was made of your device so you will not have to start over completely from scratch.
    Hope this helps!

  • Unable to open PDF files with Adobe Reader, Mac trying to open files with Quicktime instead, but not succeeding. HELP!

    Unable to open PDF files with Adobe Reader, Mac trying to open files with QuickTime instead, but not succeeding. HELP!

    Hi BDAqua,
    Thanks for the info, I dragged a PDF to desktop ctrl-, get info. change all to open with adobe.
    Problem solved, many thanks for a quick response.
    Barry69

  • Developer: How can I let people open files with my program?

    Hello Everyone,
    I just finished my program for the Mac, and decided to make it an application.
    I used Platypus to make my program into an application. Unfortunately when I try to open a file with my program (control + click on file + open with -> other), my application is grayed out and I can't select it. I see it there along with the other applications but I can't select it like I can Mail or TextEdit.
    I read somewhere I had to use XCode to let people open files with my program but I have never used XCode and I have no idea how to do that. Any help would be appreciated.
    Thanks,
    Nick

    You've posted in the wrong forum. This is the OS X Leopard Installation and Setup forum. You need to post your problem in the Developers forum. Also, since Platypus is not an Apple product, you should visit it's developers forum for assistance. The Apple Discussions is intended to assist users with problems and questions about Apple products only.
    To use XCode Tools you need to install it from the Optional Installs folder on your OS X Installer Disc One. It comes with documentation. More assistance can be found at developer.apple.com.

Maybe you are looking for