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 8892843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:06:29+00:00 2026-06-14T23:06:29+00:00

This is the class that’s about to be serialized into a byte array. public

  • 0

This is the class that’s about to be serialized into a byte array.

public class DummyClass implements Serializable
{
    private static transient final long serialVersionUID    = -8483859843874771619L;
    public String   y;

    public DummyClass(String y)
    {
        this.y = y;
    }
    public String getY()
    {
        return this.y;
    }
}

This is the Serialization execution test

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutput out = null;
    byte[] bs = null;
    try
    {
        DummyClass dummyClass = new DummyClass("World I Salute you");
        out = new ObjectOutputStream(bos);
        out.writeObject(dummyClass); // <--- Throws exception here
        bs = bos.toByteArray();
    }
    finally
    {
        out.close();
        bos.close();
    }

and regarding the stack trace:

java.io.NotSerializableException: tests.DummyClassTest
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at tests.DummyClassTest.dummyTest(DummyClassTest.java:109)

The Obvious question is what am i doing wrong?

Cheers.

EDIT:

The whole Class

public class DummyClassTest
{
    public class DummyClass implements Serializable
    {
        private static transient final long serialVersionUID    = -8483859843874771619L;
        public String   y;

        public DummyClass(String y)
        {
            this.y = y;
        }
        public String getY()
        {
            return this.y;
        }
    }

    @Test
    public void dummyTest() throws IOException
    {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = null;
        byte[] bs = null;
        try
        {
            DummyClass dummyClass = new DummyClass("World I Salute you");
            out = new ObjectOutputStream(bos);
            out.writeObject(dummyClass);
            bs = bos.toByteArray();
        }
        finally
        {
            out.close();
            bos.close();
        }
    }
}
  • 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-06-14T23:06:30+00:00Added an answer on June 14, 2026 at 11:06 pm

    A non-static inner class has an implicit reference to its outer class instance. So when you serialize DummyClass, you’re also serializing this implicit reference to the DummyClassTest instance owning it.

    Define the DummyClass as a top-level class (non nested), or as a static inner class, and everything will work as expected.

    The following:

    public class DummyClassTest {
        public class DummyClass {
        }
    }
    

    is more or less equivalent to

    public class DummyClassTest {
    }
    
    public class DummyClass {
        private DummyClassTest outerInstance;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have this class that another programmer in my team coded: public static
I have this class that implements FilenameFilter package Logic; import java.io.File; import java.io.FilenameFilter; public
I have a javascript class that I'm creating. This class has private and public
I have a PHP class that looks like this: class userAuthentication { public static
I have class that looks like this: class A { public: class variables_map vm
Assume I have a class that looks like this: class Sample { public string
I have a Handler class that looks like this: class Handler{ public $group; public
I have this class that has a static member. it is also a base
I've a class that basically looks like this: class App { public function newTemplate($filename,
I've implemented a class that looks like this interface: [ImmutableObject(true)] public interface ICustomEvent {

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.