Transform a map into an object.
Transform a map into an object.
the map
the desired class name
true
to recursively map nested maps, false
otherwise. Recursively mapped maps will have generated
class names.
an instantiated object representing the map
Transform a map into an object.
Transform a map into an object. The class name will be generated,
will be in the org.clapper.classutil
package, and will have
a class name prefix of MapBean_
.
the map
true
to recursively map nested maps, false
otherwise
an instantiated object representing the map
Takes a Scala
Map
, withString
keys and object values, and generates a Java Bean object, with fields for each map value. Field that are, themselves,Map[String,Any]
objects can be recursively mapped, as well. The map's keys are mapped to Java Beanget
accessors. For instance, a key name "foo" is mapped to a method calledgetFoo()
.The transformation results in an object that can only really be used via reflection; however, that fits fine with some APIs that want to receive Java Beans as parameters.
There are some restrictions imposed on any map that is to be converted.
- Only maps with string keys can be converted. - The string keys must be valid Java identifiers.
Here's a simple example:
That Scala script will produce output like the following: