Try regex or split by special char. First remove parentheses from beginning and end. After that you can split it by ,
and =
to collect strings to map.
String userAttributes = "[{name=test, cp=458999, lastname=test2}]";
List<String> strings = Arrays.asList(userAttributes
.replace("[{","").replace("}]","")
.split(", "));
Map<String, String> collect = strings.stream()
.map(s -> s.split("="))
.collect(Collectors.toMap(s -> s[0], s -> s[1]));
System.out.println(collect.get("name"));
Other approach with Pattern
Map<String, String> collect = Pattern.compile(",")
.splitAsStream(userAttributes
.replace("[{","").replace("}]",""))
.map(s -> s.split("="))
.collect(Collectors.toMap(s -> s[0], s -> s[1]));
Or if you really wants use List<Map<String, String>>>
. But after that you can not do this user.setUserName(attributes.get("name"));
List<Map<String, String>> maps = strings.stream()
.map(s -> s.split("="))
.map(s -> Map.of(s[0], s[1]))
.collect(Collectors.toList());
System.out.println(maps);