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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:44:24+00:00 2026-05-15T23:44:24+00:00

I have a complex Clojure data structure that I would like to serialize –

  • 0

I have a complex Clojure data structure that I would like to serialize – basically the entire current game state for an online game I am developing so that I can implement save game files.

My requirements are:

  • Some form of human-readable text format (I’d probably prefer s-expressions, JSON and XML in that order but open to others)
  • Support all the usual Clojure data structures, keywords and primitives
  • Ability to provide custom serialization / deserialization functions for custom java classes, defrecords etc. (this is important because I need to do something like Java’s readResolve in several cases)
  • Good performance is a nice-to-have

Any good recommendations?

  • 1 1 Answer
  • 1 View
  • 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-15T23:44:24+00:00Added an answer on May 15, 2026 at 11:44 pm

    If you wanted to serialize things to S-expressions, you could use print-dup:

    (binding [*print-dup* true] (println [1 2 3]))
    ; prints [1 2 3]
    
    (defrecord Foo [x])
    ; => user.Foo
    (binding [*print-dup* true] (println (Foo. :foo)))
    ; prints #=(user.Foo/create {:x :foo})
    

    Note that printing a structure which holds, say, ten references to a single vector followed by reading it back gives you a datastructure with ten separate (not identical?), though equivalent in terms of structure (=) vectors.

    To use this in cases where there is no default implementation provided, implement the multimethod clojure.core/print-dup.

    Also, a lot of things in Clojure 1.2 are java.io.Serializable:

    (every? (partial instance? java.io.Serializable)
            [{1 2} #{"asdf"} :foo 'foo (fn [] :foo)])
    ; => true
    
    (defrecord Foo [])
    (instance? java.io.Serializable (Foo.))
    ; => true
    

    Note that you should avoid serializing runtime-created fns — they are instances of one-off classes with weird names and you won’t be able to deserialize them after restarting your JVM anyway. With AOT compilation, fns do get their own fixed classnames.

    Update: As mentioned in a comment on the question, Serializable is best suited to short-term storage / transfer of data, whereas print-dup should be more robust as a long-term storage solution (working across many versions of the application, Clojure etc.). The reason is that print-dup doesn’t in any way depend on the structure of the classes being serialized (so a vector print-dup‘d today will still be readable when the vector implementation switches from Java to Clojure’s deftype).

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

Sidebar

Related Questions

I have complex data structure, like this: OrderedHash, keys are dates and values are
I have several complex data structures like Map< A, Set< B > > Set<
I am looking for a way to have complex URL mappings that would depend
I have complex logical expression that look like this: ((((!((cond1) || (cond2) || (cond3))
I have complex-type object of entity framework. I would like buid dynamically select and
We have a complex app that serves AJAX JSON streams (using ADO to grab
I have a complex RIA client that communicates with a WCF SOAP web service,
Here is the problem: I have a very complex plugin that does lots of
i have complex xslt that formats xml to html now i need to be
Suppose I have complex objects, like structs containing a huge amount of members -

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.