+1 on @david's comment.

Why not use JSON end-to-end and derive the type desired for each individual rule? Then use a single function to transform a JSON value to the correct type (using defaults or Option when it doesn't really match).

Then you can use something like this to run the ruleset over all of the parsed objects:

for (object <- parseObjects(); rule <- rules) {
  val value = coerce(object, rule.desiredType)

Or something similar, such as having the rule itself call the coercion code. It seems like you don't really need the objects to have a type until you're doing rule processing, so why try to?

P.S. Typesafe Config may be able to parse the file for you already, although it looks to be a simple format to parse.

Related Query

More Query from same tag