how to convert LinkedHashMap to Custom java object?

前端 未结 3 1201
孤独总比滥情好
孤独总比滥情好 2020-12-29 21:49

I\'m trying to get the data from one app to another via RESTful WS and it works, but I cannot use this data since I cannot cast it... WS returns a List of objects like this:

3条回答
  •  一个人的身影
    2020-12-29 22:09

    import:

    import com.fasterxml.jackson.databind.ObjectMapper;
    

    object:

    private ObjectMapper mapper = new ObjectMapper();
    

    examples:

    PremierDriverInfoVariationDTO premierDriverInfoDTO = 
    mapper.convertValue(json, PremierDriverInfoVariationDTO.class); 
    log.debug("premierDriverInfoDTO : {}", premierDriverInfoDTO);
    

    or

    Map map = mapper.convertValue(json, Map.class);
    log.debug("result : {}", map);
    assertFalse(map.get("eligiblePDJob"));
    

提交回复
热议问题