2

I am using Spring-boot Application where I am able to connect with Azure App Configuration. But getting the error when I try to read value with content-type application/JSON.

My Java Class

@ConfigurationProperties(prefix = "config")
    @Getter
    @Setter
    public class AppConfigProperties {
        private String test;
        private Map<String, Map<Integer, List<Integer>>> map;
 }

App configuration

key: map
value: {"Cream":{"1":[2,3,4],"2":[25]},"Ice":{"1":[2,3,4],"2":[25]}}
content type = application/json

Error :


Description:

Failed to bind properties under 'config.map' to java.util.Map<java.lang.String, java.util.Map<java.lang.Integer, java.util.List<java.lang.Integer>>>:

    Reason: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.util.Map<java.lang.Integer, java.util.List<java.lang.Integer>>>]

Action:

Update your application's configuration
suraj jain
  • 21
  • 6
  • It seems Spring doesn't try to parse the json hence "`String` cannot be converted to `Map`". Btw, `{1, 2, 3}` is _not_ valid json, it should be `[1, 2, 3]`. – Thomas Oct 27 '21 at 09:09
  • @Thomas I have changed the JSON but still have the same problem, I want to know is their any annotation or any configuration through which I can read the value in map variable – suraj jain Oct 27 '21 at 10:06
  • How are you getting the config from Azure? And what does it return, the json only or everything you've provided under "App configuration"? – Thomas Oct 27 '21 at 11:08
  • 1
    @surajjain this seems to be a bug on the App Configuration Client Library. You should report the bug here https://github.com/Azure/AppConfiguration/issues. – mrm9084 Oct 27 '21 at 21:23

1 Answers1

0

Instead of converting string & integer. You can use as an object.

You can easily convert object into other datatypes.

private Map<String, Map<Integer, List>> map;

You can use

@JsonIgnore
private Map<String, Object> properties = new HashMap<String, Object>();

Refer here

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15