Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3977118
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:53:07+00:00 2026-05-20T04:53:07+00:00

I have a class that is something like the following: public class Foo {

  • 0

I have a class that is something like the following:

public class Foo {
  static byte[] convertToArray(Foo f);
  static Foo convertToFoo(byte[] ba);
}

How can I use convertToArray and convertToFoo to allow Foo to implement java.io.Serializable? The default serialization procedure doesn’t seem like a good solution for my class because it would require changing a lot of other classes to implement Serializable. However, I already have a way to go to and from bytes, so there should be an easy way for Foo to implement serializable without having to declare all dependent members as Serializable. I suspect overriding readObject and writeObject is the way to go, but what is the correct way to do this, since these are instance methods with return type void?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:53:08+00:00Added an answer on May 20, 2026 at 4:53 am

    Check out Externalizable, which is a subinterface of Serializable. Its readExternal and writeExternal methods delegate the serialization details to the programmer, which sounds appropriate in your case.

    During deserialization (in your implementation of readExternal), you will need to use Foo.convertToFoo to convert the bytes from an ObjectInput to a Foo object, and then copy all of the state of that Foo object into this.

    A snippet from the Javadoc that describes the semantics of Externalizable:

    Only the identity of the class of an
    Externalizable instance is written in
    the serialization stream and it is the
    responsibility of the class to save
    and restore the contents of its
    instances. The writeExternal and
    readExternal methods of the
    Externalizable interface are
    implemented by a class to give the
    class complete control over the format
    and contents of the stream for an
    object and its supertypes. These
    methods must explicitly coordinate
    with the supertype to save its state.
    These methods supersede customized
    implementations of writeObject and
    readObject methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following situation class base { public: virtual void Accepted(SOCKET s) //// Event
I have the following domain object: public class Bank : IEntity { } And
I have some files that contain logs of objects. Each file can store objects
As you can't have an array in a define or a class constant I
In a generic C# class for an internal reusable library, I'd like to pass
I have a pretty simple problem with a not-so-obvious solution. I have a relational
So I'm attempting to use a combination of MEF and Ninject in an application
I am working on an object that contains an array of queues with an
I'm developing a RIA application where there is javascript on the client (i'm using
I stumbled upon this while trying to build an ActiveX dll from an old

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.