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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:08:41+00:00 2026-06-12T16:08:41+00:00

Java contains a lot of classes (like in Swing) which implement the dreaded and

  • 0

Java contains a lot of classes (like in Swing) which implement the dreaded and error prone interface Serializable.

If you implement, say, a new TableModel by extending AbstractTableModel, the new model must be serializable but what if it contains internal data types which aren’t serializable and which don’t have to be since you don’t plan to use this feature anyway?

In such a case, tools like Sonar go crazy. The either complain that “Class Foo defines non-transient non-serializable instance field bar“.

So I make that field transient just to get “The field Foo.bar is transient but isn’t set by deserialization”

Is it possible to say “No, this class isn’t serializable, and I don’t want it to be” in such a way that you don’t get any errors in tools like Sonar?

  • 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-12T16:08:42+00:00Added an answer on June 12, 2026 at 4:08 pm

    Quoting from this JavaRevisited article (see #8):

    To avoid java serialization you need to implement writeObject() and readObject() method in your Class and need to throw NotSerializableException from those method.

    So you just need to paste this into your class:

    private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {
        throw new java.io.NotSerializableException( getClass().getName() );
    }
    
    private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException {
        throw new java.io.NotSerializableException( getClass().getName() );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application jar contains classes from swing-layout.jar which contains free layout manager for java
I developed a java web application which contains Wallpapers, there is like button for
I am doing a project in Java Swing. I have a JDialog which contains
I have a java package which contains all my test case classes. Each class
I'm looking for a js library like StringUtils of commons-lang in java, which contains
In some old Java code, I found a class that contains a lot of
The index.jsp contains java codes which will fetch some images and texts from a
I have a master report which contains a lot of information and I need
I have a script ( Java String) that contains a lot of SQL and
We have received Java code from a software supplier. It contains a lot of

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.