Please review the attached YAML file for sample properties. Note the default profile has an array of PromoCode objects defined. When a SpringBoot application is configured to talk to the Config Server with the appropriate profile, you get the correct response. However, when you request the properties or yaml view, you get a mixed array of the 2 profiles.

http://localhost:8888/promoCodes/default - produces correct json
http://localhost:8888/promoCodes/dev - produces correct json

Alternate views produce correct results for default profile

http://localhost:8888/promoCodes-default.properties

promos.promoCards[0].client: Google Nexus 6P     <----
promos.promoCards[0].description: Free stuff for Google users     <----
promos.promoCards[0].endDate: 2016-04-26T20:01:30.781Z     <----
promos.promoCards[0].image: http://google.com/images/coolpic.jpg     <----
promos.promoCards[0].name: P1     <----
promos.promoCards[0].platform: Android     <----
promos.promoCards[0].startDate: 2016-04-26T20:01:30.781Z     <----
promos.promoCards[0].thumbnail: http://google.com/images/coolpic.jpg     <----
promos.promoCards[1].client: Google Nexus 5X
promos.promoCards[1].description: Free stuff for Google users
promos.promoCards[1].endDate: 2016-04-26T20:01:30.781Z
promos.promoCards[1].image: http://google.com/images/coolpic.jpg
promos.promoCards[1].name: P2
promos.promoCards[1].platform: Android
promos.promoCards[1].startDate: 2016-04-26T20:01:30.781Z
promos.promoCards[1].thumbnail: http://google.com/images/coolpic.jpg
promos.promoCards[2].client: iPhone 6S
promos.promoCards[2].description: Expensive stuff from Steve
promos.promoCards[2].endDate: 2016-04-26T20:01:30.781Z
promos.promoCards[2].image: http://apple.com/images/coolpic.jpg
promos.promoCards[2].name: P3
promos.promoCards[2].platform: iOS 9
promos.promoCards[2].startDate: 2016-04-26T20:01:30.781Z
promos.promoCards[2].thumbnail: http://apple.com/images/coolpic.jpg
promos.promoCards[3].client: Nokia Lumia 8610
promos.promoCards[3].description: Bad stuff for windoze users
promos.promoCards[3].endDate: 2016-04-26T20:01:30.781Z
promos.promoCards[3].image: http://microsoft.com.com/images/coolpic.jpg
promos.promoCards[3].name: P4
promos.promoCards[3].platform: Windoze
promos.promoCards[3].startDate: 2016-04-26T20:01:30.781Z
promos.promoCards[3].thumbnail: http://microsoft.com.com/images/coolpic.jpg

Alternate views produce incorrect results for dev profile

http://localhost:8888/promoCodes-dev.properties

promos.promoCards[0].client: Nokia Lumia 8888     <----
promos.promoCards[0].description: Bad stuff for windoze users     <----
promos.promoCards[0].endDate: 2016-04-26T20:01:30.781Z     <----
promos.promoCards[0].image: http://microsoft.com.com/images/coolpic.jpg     <----
promos.promoCards[0].name: P4     <----
promos.promoCards[0].platform: Windoze     <----
promos.promoCards[0].startDate: 2016-04-26T20:01:30.781Z     <----
promos.promoCards[0].thumbnail: http://microsoft.com.com/images/coolpic.jpg     <----
promos.promoCards[1].client: Google Nexus 5X
promos.promoCards[1].description: Free stuff for Google users
promos.promoCards[1].endDate: 2016-04-26T20:01:30.781Z
promos.promoCards[1].image: http://google.com/images/coolpic.jpg
promos.promoCards[1].name: P2
promos.promoCards[1].platform: Android
promos.promoCards[1].startDate: 2016-04-26T20:01:30.781Z
promos.promoCards[1].thumbnail: http://google.com/images/coolpic.jpg
promos.promoCards[2].client: iPhone 6S
promos.promoCards[2].description: Expensive stuff from Steve
promos.promoCards[2].endDate: 2016-04-26T20:01:30.781Z
promos.promoCards[2].image: http://apple.com/images/coolpic.jpg
promos.promoCards[2].name: P3
promos.promoCards[2].platform: iOS 9
promos.promoCards[2].startDate: 2016-04-26T20:01:30.781Z
promos.promoCards[2].thumbnail: http://apple.com/images/coolpic.jpg
promos.promoCards[3].client: Nokia Lumia 8610
promos.promoCards[3].description: Bad stuff for windoze users
promos.promoCards[3].endDate: 2016-04-26T20:01:30.781Z
promos.promoCards[3].image: http://microsoft.com.com/images/coolpic.jpg
promos.promoCards[3].name: P4
promos.promoCards[3].platform: Windoze
promos.promoCards[3].startDate: 2016-04-26T20:01:30.781Z
promos.promoCards[3].thumbnail: http://microsoft.com.com/images/coolpic.jpg

Note the difference in promos.promoCards[0] between the 2 results indicated by <----.

The desired output should be for the dev profile:

http://localhost:8888/promoCodes-dev.properties

promos.promoCards[0].client: Nokia Lumia 8888
promos.promoCards[0].description: Bad stuff for windoze users
promos.promoCards[0].endDate: 2016-04-26T20:01:30.781Z
promos.promoCards[0].image: http://microsoft.com.com/images/coolpic.jpg
promos.promoCards[0].name: P4
promos.promoCards[0].platform: Windoze
promos.promoCards[0].startDate: 2016-04-26T20:01:30.781Z
promos.promoCards[0].thumbnail: http://microsoft.com.com/images/coolpic.jpg

The issue occurs in org.springframework.cloud.config.server.environment.EnvironmentController, specifically convertToProperties(Environment environment):

private Map<String, Object> convertToProperties(Environment profiles) {
    Map<String, Object> map = new TreeMap<>();
    List<PropertySource> sources = new ArrayList<>(
            profiles.getPropertySources());
    Collections.reverse(sources);
    for (PropertySource source : sources) {
        @SuppressWarnings("unchecked")
        Map<String, String> value = (Map<String, String>) source.getSource();
        map.putAll(value);                               <-- (No checking for existing array from earlier profile with same name)
    }
    postProcessProperties(map);
    return map;
}

The issue is the for loop over the PropertySources. The Map value has a key that contains all the individual promos.promoCards[X] entries individually and puts them all on each iteration into a final map, replacing any duplicates. However, in the case of a YAML list, it should also be checking if any other 'promos.promoCards[' exists as keys and remove them before adding all of the current iteration to the resulting map.

promoCodes.yml.txt

Comment From: spencergibb

When you say

(No checking for existing array from earlier profile with same name)

Do you mean an existing array with the same name from an earlier property source?

Comment From: dmfrey

@spencergibb yes, for instance, in the default profile you have an array established as such: promos.promoCards[0].client. If this is the case, then any other promos.promoCards[X]: should be removed before doing the putAll on the map.

You should be able to take the attached yml, put it in any Config Server git repo and see the result by hitting the different endpoints.

Comment From: dsyer

I think this is asking too much of the properties endpoints (i.e. it's not supported and isn't really supposed to be). If you have a proposal about how to improve it, we can treat it as an enhancement (pull requests welcome).

Comment From: dmfrey

@dsyer I think this a bug, rather than an enhancement. It is a data consistency issue. When you request the normal JSON endpoint, you get the desired results. However, when you request properties or YAML, with the supplied config file, you get a mix of the data provided by the default profile and the dev profile. The array of properties returned with the dev profile replaced the first element in the default array with the only item in the dev array, yet all the other default items in the array remain in the final output.

I have the code pulled down and need to get it into STS or Intellij to play with it. Hopefully, I can get a PR out there for it.

Comment From: velykov

+1 I've just got a same bug

plan:
  - ids: 1, 2, 3, 4, 5
    responses:
      - t1: "type1"
        resp: "response 1"
      - t2: "type2"
        resp: "response 2"
      - t3: "type3"
        resp: "response 3"
    default-resp: "default response"
  - ids: 7
    resp: "response 7"

If I call regular endpont, I got a correct answer with array in responses, but if I call a json endpoint, I'we got a map in response, WTF?

Comment From: dsyer

This issue was closed as "fixed" more than 4 years ago. If you are experiencing a problem with the latest version, it would be better to open a new issue as it's unlikely to be related.

Comment From: velykov

Yep, thank you