Search code examples
scalaconfigtypesafe

Typesafe config load from java.util.prefs.Preferences


I'm trying to figure out how to properly instantiate a Config instance using a java.util.prefs.Preferences object.

The API exposes a ConfigFactory.load() method that takes a java.util.Properties parameter, but for the life of me I can't figure out how to do the Preferences to Properties conversion.

Do you guys have any hints?

P.S. I get the preferences object as a parameter from an external context and modifying it to something more convenient is not really an option.


Solution

  • There seems to be no direct way to do it. Implementing ConfigParseable to add new kinds of file formats/APIs is very explicitly not supported.

    The easiest thing I can think is to write your own method for converting Preferences to Properties recursively, using childrenNames() and keys().