lightbend / config

configuration library for JVM languages using HOCON files
https://lightbend.github.io/config/
6.12k stars 968 forks source link

Feature: support java records in addition to java beans as config objects #769

Open pjroth opened 2 years ago

pjroth commented 2 years ago

ConfigBeanFactory.create supports the ability to create a typed object with a single method call which is very nice. I am using java 17 and would like to use a record instead of a java bean to take advantage of the much reduced boilerplate possible when using java records.

My proposal is something along the lines of the following:

record MyConfig(String uri, Integer port);

var map = Map.of(
                "uri", "localhost",
                "port", "1234");
var fullConfig = ConfigFactory.parseMap(map)
var myConfig = ConfigRecordFactory.create(fullConfig, MyConfig.class);

assertThat(myConfig.uri(), equalTo("localhost"));
assertThat(myConfig.port(), equalTo("1234"));

Thanks for this great library!

laglangyue commented 1 year ago

I alse need this feature.

mkurz commented 1 year ago

I think you should provide a pull request if you want to see this happen.