Results 1 to 6 of 6
  1. #1
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Posts
    45
    Rep Power
    0

    Default Prevent default write object serialization

    I've got a class that overrides writeObject so that it can serialize across a network to a C client. However, when it writes itself, it first writes the default as if I hadn't overridden writeObject and THEN it writes my implementation. I don't want it to write the default.

    Java Code:
    import java.io.*;
    public class SomeClass implements Serializable, ObjectStreamConstants {
    ...
    private void writeObject(ObjectOutputStream out) throws IOException {
         out.writeByte(TC_OBJECT);
         out.writeUTF("SomeClass");
    }
    ...
    In the server class I get the output stream from the socket, cast an ObjectOutputStream and then send an instance of SomeClass.

    Java Code:
    try {
         SomeClass sc = new SomeClass();
         out.writeObject(sc);
    } catch (IOException ioe) {
    }
    What the client receives is:
    AC ED 00 05
    not sure if this is the handshake leftovers?
    73 72 00 ... 73 00 09 53 6F 6D 65 43 6C 61 73 73 78
    I've replaced part of the long default data with ... and then it continues with what I told it to write and ends with the end block constant.

  2. #2
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Posts
    45
    Rep Power
    0

    Default

    Yes. The top code block is part of the SomeClass class. The bottom code block is what is happening in the server. I implement writeObject in SomeClass, so I'd expect only that to run when I write a SomeClass object to the stream. But it's doing its own thing and then doing my thing.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default

    Why are you using Serialization if you don't want it? How about the DataOutput classes?

  4. #4
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Posts
    45
    Rep Power
    0

    Default

    I was trying to avoid rewriting the server, which uses an ObjectOutputStream to send stuff to clients. Without going into too much detail, the server needs to communicate between clients written in Java as well as C. Perhaps it would be easier just to figure out how to interpret the raw data on the C side. I'd also need to be able to rebuild an object to send back to the server.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default

    Could JNI be used here?

  6. #6
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Posts
    45
    Rep Power
    0

    Default

    I've never used JNI, so can't say. I'm probably making things more complicated than they need to be. I'll do some more digging around. It looks like I will have to redesign things to make this work anyway. Thanks for your help.

Similar Threads

  1. Replies: 0
    Last Post: 03-02-2010, 08:07 AM
  2. Object serialization
    By sky in forum New To Java
    Replies: 15
    Last Post: 11-23-2009, 01:10 PM
  3. Replies: 2
    Last Post: 10-11-2009, 12:31 PM
  4. Replies: 1
    Last Post: 07-25-2009, 05:53 PM
  5. Replies: 1
    Last Post: 01-29-2009, 09:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •