0

this code works perfectly if there is no field called _transferSize, sample har :

"cookies": [
            {
              "name": "x-amz-captcha-1",
              "value": "1577615972915416",
              "path": "/",
              "expires": "2020-12-28T08:39:32.000Z",
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "x-amz-captcha-2",
              "value": "PKRgLIISQDY1ubrOgWIOQQ==",
              "path": "/",
              "expires": "2020-12-28T08:39:32.000Z",
              "httpOnly": false,
              "secure": false
            }
          ],
          "content": {
            "size": 0,
            "mimeType": "x-unknown"
          },
          "redirectURL": "/",
          "headersSize": -1,
          "bodySize": -1,
          "_transferSize": 553
        },

I was trying to get all properties by HarLib java library. code

ObjectMapper mapper = new ObjectMapper();
            mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
            System.out.println("Harpath : " + harPath);
            File f = new File(harPath);
            HarFileReader r = new HarFileReader();
            HarLog log = r.readHarFile(f);
            HarEntries entries = log.getEntries();
            System.out.println(entries);

            //          HarHeaders s =  entries.getEntries().get(1).getResponse().getHeaders();
            //          List<HarHeader> ss = s.getHeaders();
            //          for (HarHeader harHeader : ss) {
            //              System.out.println(harHeader.getValue());
            //          }

            //          System.out.println("elements on entries : " + entries.getEntries().size());
            //System.out.println(ss.get(5).getName() +"="+ss.get(5).getValue());

can anyone help me to get values of each KEYS, so that can get map and get all values?

Nick
  • 689
  • 14
  • 27

1 Answers1

0

It seems like you tried to customize the ObjectMapper but actually never used it. Try something like this:

ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

// ...

File f = new File(harPath);
JsonParser parser = mapper.getFactory().createParser(f);
List<HarWarning> warnings = new ArrayList<HarWarning>();
HarLog log = r.readHarFile(parser, warnings);

// ...
Mafor
  • 9,668
  • 2
  • 21
  • 36
  • now it is showing an exception like "The method readHarFile(org.codehaus.jackson.JsonParser, java.util.List) in the type HarFileReader is not applicable for the arguments (com.fasterxml.jackson.core.JsonParser, java.util.List)" – Nick Dec 29 '19 at 17:46
  • @Nick Ok, so HarLib uses a very old version of the Jackson library. You may try to replace `com.fasterxml.jackson.databind.ObjectMapper` import with `org.codehaus.jackson.map.ObjectMapper`. The same for `JsonParser`. – Mafor Jan 04 '20 at 12:00