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

  • Home
  • SEARCH
  • 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 6872011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:52:28+00:00 2026-05-27T03:52:28+00:00

I am trying to serialize some objects of class InstitutionResultView which is basically wrapper

  • 0

I am trying to serialize some objects of class InstitutionResultView which is basically wrapper to guava’s TreeMultimap:

import java.io.Serializable;
import java.text.Collator;
import java.util.Comparator;

import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.collect.Maps.EntryTransformer;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Ordering;
import com.google.common.collect.SortedSetMultimap;
import com.google.common.collect.TreeMultimap;

public class InstitutionResultView implements Serializable {
  private static final long serialVersionUID = -8110992296090587657L;

  private final SortedSetMultimap<String, Institution> nameToInstitutionsMapping = TreeMultimap.create(
      Ordering.from(StringComparators.AS_IS), // insertion order
      Ordering.natural() // <----- this works when serializing object
      // Ordering.from(Collator.getInstance()) // <----- when used instead previous line gives an exception when serializing
          .nullsFirst().onResultOf(StringInstitutionFunctions.BY_NAME) // sort by name
          .compound(
              Ordering.natural().nullsFirst().onResultOf(IntegerInstitutionFunctions.BY_ID) // sort by id
              ));

  public SortedSetMultimap<String, Institution> institutions() {
    return nameToInstitutionsMapping;
  }

  public void setInstitutions(final Multimap<String, Institution> institutions) {
    this.nameToInstitutionsMapping.clear();
    this.nameToInstitutionsMapping.putAll(institutions);
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this)
        .add("nameToInstitutionsMapping", Multimaps.transformEntries(nameToInstitutionsMapping, EntryTransformers.TO_NAME_WITH_CATEGORY))
        .toString();
  }

During serialization I get exception:

java.io.NotSerializableException: java.text.RuleBasedCollator at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
at

…

com.google.common.collect.TreeMultimap.writeObject(TreeMultimap.java:180)

…

I found this bug from Sun’s bug database which covers very similar case to mine, but it doesn’t point to any resolution. I tried adding transient Collator instance field:

  private transient Collator collatorInstance = Collator.getInstance();

and using it as Ordering.from(collatorInstance) but still it doesn’t work.

I’d be glad if anybody could give me some idea what to do to solve this problem.


EDIT – That’s what worked for me (thanks to @Puce and his answer):

  class CollatorWrapper implements Comparator<String>, Serializable {
    private static final long serialVersionUID = 1L;

    private transient Collator collatorInstance;

    public CollatorWrapper() {
      super();
      initCollatorInstance();
    }

    @Override
    public int compare(final String o1, final String o2) {
      return collatorInstance.compare(o1, o2);
    }

    private void initCollatorInstance() {
      collatorInstance = Collator.getInstance();
    }

    private void writeObject(final java.io.ObjectOutputStream out) throws IOException {
      out.defaultWriteObject();
    }

    private void readObject(final java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
      in.defaultReadObject();
      initCollatorInstance();
    }
  }
  • 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-27T03:52:28+00:00Added an answer on May 27, 2026 at 3:52 am

    I think you might be able to write a wrapper, which

    • implements Comparator
    • implements Serialzable (and the necessary methods such as readObject, writeObject)
    • wraps a transient Collator
    • remembers the Locale (if you need that)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to serialize some objects obtained from a 3rd Party .NET Lib to
I'm trying to build a Lucene Serializer class that would serialize/de-serialize objects (classes) with
I am trying to use MOXy JAXB to serialize a class A which looks
I'm trying to figure out a way to serialize some Django model object to
I've run into some problems when trying to serialize my object to XML. The
I have an XML file that I'm trying to serialize into an object. Some
I'm trying to serialize a custom class that needs to use multiple elements of
What I'm trying to do is, make the class message serialize and deserialize it's
Here are some models I am trying to load data for: class School(models.Model): name
I am trying to transmit objects of a particular class from one server to

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.