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
  • 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-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

Ask A Question

Stats

  • Questions 477k
  • Answers 477k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the client's code is already in a DLL, you… May 16, 2026 at 5:08 am
  • Editorial Team
    Editorial Team added an answer No - static constructors will only be called the first… May 16, 2026 at 5:08 am
  • Editorial Team
    Editorial Team added an answer Not really answering your question, but if you want to… May 16, 2026 at 5:08 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top 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.