8

I have a YAML configuration file with a map of properties:

properties:
  a.b.c: 1

Boot will parse this as:

{a:{b:{c:1}}}

However, what I desire is :

{'a.b.c': 1}

Is there anyway to coax it into "pass through" key mode? Quoting the key doesn't seem to help.


Update

Actual example below.

Java

import static com.google.common.collect.Maps.newLinkedHashMap;

import java.util.Map;
import javax.annotation.PostConstruct;

import lombok.Data;
import lombok.val;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties("hadoop")
public class HadoopProperties {

   private Map<Object, Object> properties = newLinkedHashMap();

}

YAML

application.yml:

hadoop:
   properties:
      fs.defaultFS: hdfs://localhost:8020
      mapred.job.tracker: localhost:8021

Result

Calling toString() on the resulting object:

HadoopProperties(properties={fs={defaultFS=hdfs://localhost:8020}, mapred={job={tracker=localhost:8021}}})

btiernay
  • 7,873
  • 5
  • 42
  • 48
  • I'm not sure where you are seeing `{a:{b:{c:1}}}`. The normal usage of YAML in Spring Boot flattens it to `Properties` so it would only be one level deep. Can you show some code? – Dave Syer Apr 29 '14 at 08:04
  • @DaveSyer updated to add actual code example – btiernay Apr 29 '14 at 13:43
  • 1
    I see. It's because you are binding to a very generic object, so Spring Boot thinks your period separators are map key dereferences. What happens if you bind to `Map` or `Properties`? – Dave Syer Apr 29 '14 at 14:47
  • @DaveSyer Seems to work with `Map`, but not `Properties`. Thanks for the pointer! – btiernay Apr 29 '14 at 17:15
  • I see the same problem, but I already have Map and still have the problem. – Robin Oct 29 '15 at 18:11

2 Answers2

3

I see. It's because you are binding to a very generic object, so Spring Boot thinks your period separators are map key dereferences. What happens if you bind to Map or Properties?

Dave Syer
  • 56,583
  • 10
  • 155
  • 143
3

you can use as below

hadoop:
   properties:
      "[fs.defaultFS]" : hdfs://localhost:8020
      "[mapred.job.tracker]": localhost:8021

reference - link

Chamly Idunil
  • 1,848
  • 1
  • 18
  • 33