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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:34:34+00:00 2026-05-31T15:34:34+00:00

I know that there is Jerkson and scalaxb and even Java’s XStream that successfully

  • 0

I know that there is Jerkson and scalaxb and even Java’s XStream that successfully able to serialize scala’s data. I know that they handle well Strings, Integers and even case classes pretty well. But if I have function as one of the fields?

e.g. if I have something like:

case class Foo(bar: (Int) => Boolean, baz: Int) 

Can these fields been somehow serialized to JSON or XML (actually, I don’t care to which one, they should be human-readable, thats why I don’t want to use SBinary)?

EDIT

Why would I want to do that?
Right now I’m writing implementation of decision tree. I don’t want to reconstruct that trees every time from training data hence I need to serialize them and that part could be done with SBinary. But additionally, it would be nice if as a humans we could look at serialized tree and analyze it.

It is not so wide task as I wrote in title, yes.
What I thinking now, is to write a custom serializer (e.g. for Jerkson) with my own format, or write to string field and then parse this back.

But I though that there could be some insanely better way to perform that.

  • 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-31T15:34:36+00:00Added an answer on May 31, 2026 at 3:34 pm

    No, a function is not necessary serializable… and serializable functions are unlikely to provide a human readable serialization.

    If you want to be able to provide any kind of function, Im’ afraid there won’t be any solution. A possible workaround, if it can be used in your scenario, is to build a case class that implements Function[Int, Boolean] and thus to go back to a case class scenario.

    For example, suppose that you have isolated that all your functions check whether a integer is exactly divisible by a given integer:

    case class Mod(mod: Int) extends Function[Int, Boolean] { //the extends part is not even require
      def apply(x: Int) = x % mod == 0
    }
    
    case class Foo(bar: Mod, baz: Int)
    

    It’s clearly ultra-restrictive. But I’m afraid it’s the best you can achieve.

    According to your edit. A solution might be to have a kind of factory class:

    case class IntTest(humanReadableDescription: String) {
      def apply(x: Int) = IntTest.fromString(humanReadableDescription)(x)
    }
    
    object IntTest {
      private val fromString = Map[String, Function[Int, Boolean]] (
         "mod2" -> {x:Int => x % 2 == 0},
         "is42" -> {x:Int => x == 42}
      )
    }
    
    case class Foo(bar: IntTest, baz: Int)
    

    But here, you will lose type safety.

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

Sidebar

Related Questions

I know that there are lots of examples out there on this, but they
I know that there are exist established frameworks written in Scala for web development
I know that there are alot of mature open source Java web services frameworks
I know that there are many IoC frameworks in .net ( They are: Ninject,
I know that there is an API for Google Data that lets you interact
I know that there are many ASN.1 parser out there but they cost quite
I know that there are 6 data types in JavaScript. What are the reference
I know that there is a code to import .csv data into a mysql
I know that there is a function in Java to set Standard Output Stream
I know that there is a data type called NSTimeInterval , but this is

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.