Java code List Map, HashMap, JSON parser snippet

  1 package com.newegg.ec.solr.eventsalestoreservice.tuple;
  2 
  3 import kafka.message.MessageAndMetadata;
  4 
  5 public class DispatcherCell_inProgress extends Cell{
  6     public DispatcherCell_inProgress(MessageAndMetadata<byte[], byte[]> mm) {
  7         super(mm);
  8     }
  9 
 10     /*
 11     static {
 12         mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
 13         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 14         mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
 15         mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
 16         mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
 17     }
 18     */
 19 
 20     /*
 21     public HashMap<String, Object> getSingleContent() throws IOException {
 22         Map<String, Object> map  = getParseMap(this.getCELL_CONTENT());
 23         map.forEach((k,v)->{
 24             if(k.equalsIgnoreCase("EntityOrList")){
 25                 try {
 26                     currentContentMap = mapper.readValue(String.valueOf(v), HashMap.class);
 27                 } catch (IOException e) {
 28                     e.printStackTrace();
 29                 }
 30             }
 31         });
 32         return currentContentMap;
 33     }
 34 
 35     public HashMap<String, Object> getParseMap(String value) throws IOException {
 36             HashMap<String, Object> tempMap = mapper.readValue(value, HashMap.class);
 37         return tempMap;
 38     }
 39   */
 40 
 41     /*
 42     // List of Hashmap
 43     public HashMap<String, Object> getSingleContent() throws IOException {
 44 
 45         final String[] content = {""};
 46         List<HashMap<String, Object>> lists = getParseMap(this.getCELL_CONTENT());
 47         lists.forEach(item-> content[0] = (String) item.get("EntityOrList"));
 48        currentContentMap = mapper.readValue(content[0], HashMap.class);
 49 
 50         return currentContentMap ;
 51     }
 52 
 53     public List<HashMap<String, Object>> getParseMap(String value) throws IOException {
 54         List<HashMap<String, Object>> List = mapper.readValue(value, List.class);
 55         return List;
 56     }
 57 */
 58 
 59 /*
 60   public HashMap<String, Object> getSingleContent() throws IOException {
 61 
 62         final String[] content = {""};
 63         List lists = getParseMap(this.getCELL_CONTENT());
 64         lists.forEach(item-> content[0] = (String) item.get("EntityOrList"));
 65         currentContentMap = mapper.readValue(content[0], HashMap.class);
 66 
 67         return currentContentMap ;
 68     }
 69 
 70 list of list
 71     public List<List<String>> getParseMap(String value) throws IOException {
 72         List<List<String>> List = mapper.readValue(value, List.class);
 73         return List;
 74     }
 75 */
 76 
 77     /*
 78     TransactionNumber
 79     StoreType
 80     StoreID
 81     ItemNumber
 82     Description
 83     ItemType
 84     Priority
 85     Status
 86     Reserved1
 87     StoreIDvice
 88     CountryCode
 89     CompanyCode
 90     IsCombo
 91     ActiveDate
 92     ExpirationDate
 93 */
 94 
 95 //    Map of Map
 96 //    @Test
 97 //    public void getParseMap() throws IOException {
 98 //        Map<String, Map<String, Object>> currentContentMap = cell.getParseMap(cell.getCELL_CONTENT());
 99 //        currentContentMap.forEach((k,v)->System.out.println("key : " + k + " value : " + v));
100 //    }
101 
102 //  List of Map
103 //    @Test
104 //    public void getParseMap() throws IOException {
105 //        String msgBody = cell.getCELL_CONTENT();
106 //        List<HashMap<String, Object>> list = cell.getParseMap(msgBody);
107 //        list.forEach(item->log.info(item.get("Action")));
108 //        list.forEach(item->log.info(item.get("TransactionNumber")));
109 //    }
110 
111 }

 

posted @ 2019-05-16 10:49  Vincent Lee  阅读(194)  评论(0编辑  收藏  举报