How do I save a case class in my source code?
Background:
I am supposed to write a test for a mapper I wrote. Yet, my mapper gets a case class handed which has a list of hundreds of objects of another case classes as one of its attributes.
My Approach:
I would add Serializable Decorator to it as I read it described here: https://alvinalexander.com/scala/how-to-use-serialization-in-scala-serializable-trait
My Problem:
I don't have access to the case classes source. It's in a different file that I have imported.
Second Approach:
I tried to use unapply on the class, I got a long option string (About 23000 characters).
Problem, I can't turn it back to a class, mostly because as a written down string, it doesn't have quotation marks around the strings.
Has anyone a better method? Because if nothing helps, I will need to have to write my own class that can serialize, take on a string and map it back to the original case class. But since I am fairly new to Scala, I hope that that would be going overboard and Scala has a simple prebuild solution for this.
EDIT: Oh yes, I can't just add more dependencies, because it is not my project. Therefore I am looking for a standard function. (I am right now working on the "myOwnCaseClass" approach. It looks like it might be less work than I have expected above. But we'll see.
Thread
. How can it be serialized? Using some standard serialization library such as JSON serialization with external configuration (json4s, circe, play-json) might be a good idea. Or you might roll out your custom serialization basing on ideas in those libraries. - SergGrcase class
es are inherentlySerializable
(as long as its contents are). Would Java serialization format be acceptable? - stefanobaghino