String to HashMap JAVA

后端 未结 10 1344
我寻月下人不归
我寻月下人不归 2020-12-02 11:32

I have a Java Property file and there is a KEY as ORDER. So I retrieve the VALUE of that KEY using the getProperty(

10条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 12:17

    I recommend using com.fasterxml.jackson.databind.ObjectMapper (Maven repo link: https://mvnrepository.com/artifact/com.fasterxml.jackson.core) like

    final ObjectMapper mapper = new ObjectMapper();
    Map mapFromString = new HashMap<>();
    try {
        mapFromString = mapper.readValue(theStringToParse, new TypeReference>() {
            });
    } catch (IOException e) {
        LOG.error("Exception launched while trying to parse String to Map.", e);
    }
    

提交回复
热议问题