/** Unit test to check for regression of [JACKSON-18]. */
  public void testSmallNumbers() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode root = mapper.createArrayNode();
    for (int i = -20; i <= 20; ++i) {
      JsonNode n = root.numberNode(i);
      root.add(n);
      // Hmmh. Not sure why toString() won't be triggered otherwise...
      assertEquals(String.valueOf(i), n.toString());
    }

    // Loop over 2 different serialization methods
    for (int type = 0; type < 2; ++type) {
      StringWriter sw = new StringWriter();
      if (type == 0) {
        JsonGenerator gen = new JsonFactory().createGenerator(sw);
        root.serialize(gen, null);
        gen.close();
      } else {
        mapper.writeValue(sw, root);
      }

      String doc = sw.toString();
      JsonParser p = new JsonFactory().createParser(new StringReader(doc));

      assertEquals(JsonToken.START_ARRAY, p.nextToken());
      for (int i = -20; i <= 20; ++i) {
        assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
        assertEquals(i, p.getIntValue());
        assertEquals("" + i, p.getText());
      }
      assertEquals(JsonToken.END_ARRAY, p.nextToken());
      p.close();
    }
  }
 @Override
 public final MediaContent deserialize(byte[] array) throws IOException {
   JsonParser parser = constructParser(array);
   MediaContent mc = readMediaContent(parser);
   parser.close();
   return mc;
 }
예제 #3
0
  public final void copyCurrentStructure(JsonParser jp)
      throws IOException, JsonProcessingException {
    JsonToken t = jp.getCurrentToken();

    // Let's handle field-name separately first
    if (t == JsonToken.FIELD_NAME) {
      writeFieldName(jp.getCurrentName());
      t = jp.nextToken();
      // fall-through to copy the associated value
    }

    switch (t) {
      case START_ARRAY:
        writeStartArray();
        while (jp.nextToken() != JsonToken.END_ARRAY) {
          copyCurrentStructure(jp);
        }
        writeEndArray();
        break;
      case START_OBJECT:
        writeStartObject();
        while (jp.nextToken() != JsonToken.END_OBJECT) {
          copyCurrentStructure(jp);
        }
        writeEndObject();
        break;
      default: // others are simple:
        copyCurrentEvent(jp);
    }
  }
예제 #4
0
 private TwitterEntry read(JsonParser jp) throws IOException {
   // First: verify that we got "Json Object":
   if (jp.nextToken() != JsonToken.START_OBJECT) {
     throw new IOException("Expected data to start with an Object");
   }
   TwitterEntry result = new TwitterEntry();
   // Iterate over object fields:
   while (jp.nextToken() != JsonToken.END_OBJECT) {
     String fieldName = jp.getCurrentName();
     // Let's move to value
     jp.nextToken();
     if (fieldName.equals("id")) {
       result.setId(jp.getLongValue());
     } else if (fieldName.equals("text")) {
       result.setText(jp.getText());
     } else if (fieldName.equals("fromUserId")) {
       result.setFromUserId(jp.getIntValue());
     } else if (fieldName.equals("toUserId")) {
       result.setToUserId(jp.getIntValue());
     } else if (fieldName.equals("languageCode")) {
       result.setLanguageCode(jp.getText());
     } else {
       // ignore, or signal error
       throw new IOException("Unrecognized field '" + fieldName + "'");
     }
   }
   jp.close(); // important to close both parser and underlying File reader
   return result;
 }
예제 #5
0
 /**
  * Method for reading sequence of Objects from parser stream.
  *
  * @since 1.8
  */
 public <T> MappingIterator<T> readValues(URL src) throws IOException, JsonProcessingException {
   JsonParser jp = _jsonFactory.createJsonParser(src);
   if (_schema != null) {
     jp.setSchema(_schema);
   }
   DeserializationContext ctxt = _createDeserializationContext(jp, _config);
   return new MappingIterator<T>(_valueType, jp, ctxt, _findRootDeserializer(_config, _valueType));
 }
  public JsonConfigurationFileManager(
      File configurationFile, InputStream defaultConfigurationFileInputStream) {
    mConfigurationFile = configurationFile;

    // Convert InputStream to JsoneElement
    JsonReader reader = new JsonReader(new InputStreamReader(defaultConfigurationFileInputStream));
    JsonParser parser = new JsonParser();
    mDefaultConfigurations = parser.parse(reader);
  }
 private void reportIllegal(JsonParser parser, JsonToken expToken) throws IOException {
   JsonToken curr = parser.getCurrentToken();
   String msg = "Expected token " + expToken + "; got " + curr;
   if (curr == JsonToken.FIELD_NAME) {
     msg += " (current field name '" + parser.getCurrentName() + "')";
   }
   msg += ", location: " + parser.getTokenLocation();
   throw new IllegalStateException(msg);
 }
예제 #8
0
 private static void addFolder(FileSystem fs, Path p, JsonArray succeeded, JsonArray failed) {
   try {
     if (fs == null) return;
     for (FileStatus file : fs.listStatus(p)) {
       Path pfs = file.getPath();
       if (file.isDir()) {
         addFolder(fs, pfs, succeeded, failed);
       } else {
         Key k = Key.make(pfs.toString());
         long size = file.getLen();
         Value val = null;
         if (pfs.getName().endsWith(Extensions.JSON)) {
           JsonParser parser = new JsonParser();
           JsonObject json = parser.parse(new InputStreamReader(fs.open(pfs))).getAsJsonObject();
           JsonElement v = json.get(Constants.VERSION);
           if (v == null) throw new RuntimeException("Missing version");
           JsonElement type = json.get(Constants.TYPE);
           if (type == null) throw new RuntimeException("Missing type");
           Class c = Class.forName(type.getAsString());
           OldModel model = (OldModel) c.newInstance();
           model.fromJson(json);
         } else if (pfs.getName().endsWith(Extensions.HEX)) { // Hex file?
           FSDataInputStream s = fs.open(pfs);
           int sz = (int) Math.min(1L << 20, size); // Read up to the 1st meg
           byte[] mem = MemoryManager.malloc1(sz);
           s.readFully(mem);
           // Convert to a ValueArray (hope it fits in 1Meg!)
           ValueArray ary = new ValueArray(k, 0).read(new AutoBuffer(mem));
           val = new Value(k, ary, Value.HDFS);
         } else if (size >= 2 * ValueArray.CHUNK_SZ) {
           val =
               new Value(
                   k,
                   new ValueArray(k, size),
                   Value.HDFS); // ValueArray byte wrapper over a large file
         } else {
           val = new Value(k, (int) size, Value.HDFS); // Plain Value
           val.setdsk();
         }
         DKV.put(k, val);
         Log.info("PersistHdfs: DKV.put(" + k + ")");
         JsonObject o = new JsonObject();
         o.addProperty(Constants.KEY, k.toString());
         o.addProperty(Constants.FILE, pfs.toString());
         o.addProperty(Constants.VALUE_SIZE, file.getLen());
         succeeded.add(o);
       }
     }
   } catch (Exception e) {
     Log.err(e);
     JsonObject o = new JsonObject();
     o.addProperty(Constants.FILE, p.toString());
     o.addProperty(Constants.ERROR, e.getMessage());
     failed.add(o);
   }
 }
 @Override
 public MediaContent[] deserializeItems(InputStream in, int numberOfItems) throws IOException {
   MediaContent[] result = new MediaContent[numberOfItems];
   JsonParser parser = constructParser(in);
   for (int i = 0; i < numberOfItems; ++i) {
     result[i] = readMediaContent(parser);
   }
   parser.close();
   return result;
 }
 private List<Image> readImages(JsonParser parser) throws IOException {
   if (parser.nextToken() != JsonToken.START_ARRAY) {
     reportIllegal(parser, JsonToken.START_ARRAY);
   }
   List<Image> images = new ArrayList<Image>();
   while (parser.nextToken() == JsonToken.START_OBJECT) {
     images.add(readImage(parser));
   }
   verifyCurrent(parser, JsonToken.END_ARRAY);
   return images;
 }
 private List<String> readPersons(JsonParser parser) throws IOException {
   if (parser.nextToken() != JsonToken.START_ARRAY) {
     reportIllegal(parser, JsonToken.START_ARRAY);
   }
   List<String> persons = new ArrayList<String>();
   String str;
   while ((str = parser.nextTextValue()) != null) {
     persons.add(str);
   }
   verifyCurrent(parser, JsonToken.END_ARRAY);
   return persons;
 }
예제 #12
0
 protected JsonNode _bindAndCloseAsTree(JsonParser jp)
     throws IOException, JsonParseException, JsonMappingException {
   if (_schema != null) {
     jp.setSchema(_schema);
   }
   try {
     return _bindAsTree(jp);
   } finally {
     try {
       jp.close();
     } catch (IOException ioe) {
     }
   }
 }
예제 #13
0
  private void setBuildStatus(CIBuild ciBuild, CIJob job) throws PhrescoException {
    S_LOGGER.debug("Entering Method CIManagerImpl.setBuildStatus(CIBuild ciBuild)");
    S_LOGGER.debug("setBuildStatus()  url = " + ciBuild.getUrl());
    String buildUrl = ciBuild.getUrl();
    String jenkinsUrl = job.getJenkinsUrl() + ":" + job.getJenkinsPort();
    buildUrl =
        buildUrl.replaceAll(
            "localhost:" + job.getJenkinsPort(),
            jenkinsUrl); // display the jenkins running url in ci list
    String response = getJsonResponse(buildUrl + API_JSON);
    JsonParser parser = new JsonParser();
    JsonElement jsonElement = parser.parse(response);
    JsonObject jsonObject = jsonElement.getAsJsonObject();

    JsonElement resultJson = jsonObject.get(FrameworkConstants.CI_JOB_BUILD_RESULT);
    JsonElement idJson = jsonObject.get(FrameworkConstants.CI_JOB_BUILD_ID);
    JsonElement timeJson = jsonObject.get(FrameworkConstants.CI_JOB_BUILD_TIME_STAMP);
    JsonArray asJsonArray = jsonObject.getAsJsonArray(FrameworkConstants.CI_JOB_BUILD_ARTIFACTS);

    if (jsonObject
        .get(FrameworkConstants.CI_JOB_BUILD_RESULT)
        .toString()
        .equals(STRING_NULL)) { // when build is result is not known
      ciBuild.setStatus(INPROGRESS);
    } else if (resultJson.getAsString().equals(CI_SUCCESS_FLAG)
        && asJsonArray.size()
            < 1) { // when build is success and zip relative path is not added in json
      ciBuild.setStatus(INPROGRESS);
    } else {
      ciBuild.setStatus(resultJson.getAsString());
      // download path
      for (JsonElement jsonArtElement : asJsonArray) {
        String buildDownloadZip =
            jsonArtElement
                .getAsJsonObject()
                .get(FrameworkConstants.CI_JOB_BUILD_DOWNLOAD_PATH)
                .toString();
        if (buildDownloadZip.endsWith(CI_ZIP)) {
          if (debugEnabled) {
            S_LOGGER.debug("download artifact " + buildDownloadZip);
          }
          ciBuild.setDownload(buildDownloadZip);
        }
      }
    }

    ciBuild.setId(idJson.getAsString());
    String dispFormat = DD_MM_YYYY_HH_MM_SS;
    ciBuild.setTimeStamp(getDate(timeJson.getAsString(), dispFormat));
  }
 /**
  * Get the configurations from the configurations File as a {@link JsonElement}
  *
  * @return {@link JsonElement} The configuration tree contained inside the configuration File. If
  *     the File doesn't exist or an error occurred, the default configuration tree is returned
  */
 private JsonElement getConfigurationTreeFromFile() {
   if (mConfigurationFile.exists()) { // Check, if the configuration File exists on disk
     JsonParser parser = new JsonParser();
     try {
       JsonElement result = parser.parse(new FileReader(mConfigurationFile));
       if (result.isJsonObject()) { // Check if content is a valid JsonObject
         return result;
       }
     } catch (FileNotFoundException e) {
       e.printStackTrace();
     }
   }
   return mDefaultConfigurations; // If the configurations File doesn't exist on disk, return the
                                  // default configurations
 }
예제 #15
0
 protected static JsonToken _initForReading(JsonParser jp)
     throws IOException, JsonParseException, JsonMappingException {
   /* First: must point to a token; if not pointing to one, advance.
    * This occurs before first read from JsonParser, as well as
    * after clearing of current token.
    */
   JsonToken t = jp.getCurrentToken();
   if (t == null) { // and then we must get something...
     t = jp.nextToken();
     if (t == null) { // [JACKSON-99] Should throw EOFException?
       throw new EOFException("No content to map to Object due to end of input");
     }
   }
   return t;
 }
예제 #16
0
 @Then("^I parse the string and print keys and values$")
 public void i_parse_the_string_and_print_keys_and_values() throws Throwable {
   System.out.println(json);
   JsonParser parser = new JsonParser();
   JsonObject myobject = (JsonObject) parser.parse(json);
   // Accessing the value of "desc"
   System.out.println(myobject.get("desc"));
   // Deserializing the value into JSONObject
   JsonObject descValue = (JsonObject) myobject.get("desc");
   // Printing the someKey value using JsonObject
   System.out.println("SomeKey Value--" + descValue.get("someKey"));
   // Retrieving the JSON Element -- JsonElement can represent a string, array or other data types
   JsonElement someElement = descValue.get("someKey");
   // Printing a value again
   System.out.println("SomeKey Value--" + someElement.getAsString());
 }
  public void testBinary() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    final int LENGTH = 13045;
    byte[] data = new byte[LENGTH];
    for (int i = 0; i < LENGTH; ++i) {
      data[i] = (byte) i;
    }
    StringWriter sw = new StringWriter();
    mapper.writeValue(sw, BinaryNode.valueOf(data));

    JsonParser p = new JsonFactory().createParser(sw.toString());
    // note: can't determine it's binary from json alone:
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertArrayEquals(data, p.getBinaryValue());
    p.close();
  }
예제 #18
0
 /** Actual implementation of value reading+binding operation. */
 protected Object _bind(JsonParser jp)
     throws IOException, JsonParseException, JsonMappingException {
   /* First: may need to read the next token, to initialize state (either
    * before first read from parser, or after previous token has been cleared)
    */
   Object result;
   JsonToken t = _initForReading(jp);
   if (t == JsonToken.VALUE_NULL) {
     if (_valueToUpdate == null) {
       result = _findRootDeserializer(_config, _valueType).getNullValue();
     } else {
       result = _valueToUpdate;
     }
   } else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
     result = _valueToUpdate;
   } else { // pointing to event other than null
     DeserializationContext ctxt = _createDeserializationContext(jp, _config);
     JsonDeserializer<Object> deser = _findRootDeserializer(_config, _valueType);
     if (_unwrapRoot) {
       result = _unwrapAndDeserialize(jp, ctxt, _valueType, deser);
     } else {
       if (_valueToUpdate == null) {
         result = deser.deserialize(jp, ctxt);
       } else {
         deser.deserialize(jp, ctxt, _valueToUpdate);
         result = _valueToUpdate;
       }
     }
   }
   // Need to consume the token too
   jp.clearCurrentToken();
   return result;
 }
  public void testEmptyArrayWrite() throws Exception {
    StringWriter sw = new StringWriter();
    JsonGenerator gen = new JsonFactory().createGenerator(sw);

    JsonStreamContext ctxt = gen.getOutputContext();
    assertTrue(ctxt.inRoot());
    assertFalse(ctxt.inArray());
    assertFalse(ctxt.inObject());
    assertEquals(0, ctxt.getEntryCount());
    assertEquals(0, ctxt.getCurrentIndex());

    gen.writeStartArray();

    ctxt = gen.getOutputContext();
    assertFalse(ctxt.inRoot());
    assertTrue(ctxt.inArray());
    assertFalse(ctxt.inObject());
    assertEquals(0, ctxt.getEntryCount());
    assertEquals(0, ctxt.getCurrentIndex());

    gen.writeEndArray();

    ctxt = gen.getOutputContext();
    assertTrue("Should be in root, was " + ctxt.getTypeDesc(), ctxt.inRoot());
    assertFalse(ctxt.inArray());
    assertFalse(ctxt.inObject());
    assertEquals(1, ctxt.getEntryCount());
    // Index won't yet move
    assertEquals(0, ctxt.getCurrentIndex());

    gen.close();
    String docStr = sw.toString();
    JsonParser jp = createParserUsingReader(docStr);
    assertEquals(JsonToken.START_ARRAY, jp.nextToken());
    assertEquals(JsonToken.END_ARRAY, jp.nextToken());
    jp.close();

    // Ok, then array with nested empty array
    sw = new StringWriter();
    gen = new JsonFactory().createGenerator(sw);
    gen.writeStartArray();
    gen.writeStartArray();
    gen.writeEndArray();
    gen.writeEndArray();
    gen.close();
    docStr = sw.toString();
    jp = createParserUsingReader(docStr);
    assertEquals(JsonToken.START_ARRAY, jp.nextToken());
    assertEquals(JsonToken.START_ARRAY, jp.nextToken());
    assertEquals(JsonToken.END_ARRAY, jp.nextToken());
    assertEquals(JsonToken.END_ARRAY, jp.nextToken());
    assertEquals(null, jp.nextToken());
    jp.close();
  }
예제 #20
0
  private JsonArray getBuildsArray(CIJob job) throws PhrescoException {
    try {
      String jenkinsUrl = "http://" + job.getJenkinsUrl() + ":" + job.getJenkinsPort() + "/ci/";
      String jobNameUtf8 = job.getName().replace(" ", "%20");
      String buildsJsonUrl = jenkinsUrl + "job/" + jobNameUtf8 + "/api/json";
      String jsonResponse = getJsonResponse(buildsJsonUrl);

      JsonParser parser = new JsonParser();
      JsonElement jsonElement = parser.parse(jsonResponse);
      JsonObject jsonObject = jsonElement.getAsJsonObject();
      JsonElement element = jsonObject.get(FrameworkConstants.CI_JOB_JSON_BUILDS);

      JsonArray jsonArray = element.getAsJsonArray();

      return jsonArray;
    } catch (Exception e) {
      throw new PhrescoException(e);
    }
  }
예제 #21
0
 private String toJsonString() {
   final Object json = jsonParser.parseWith(createConfigurableJsonSlurper());
   final String jsonString;
   if (json instanceof Map) {
     jsonString = JsonOutput.toJson((Map) json);
   } else {
     jsonString = JsonOutput.toJson(json);
   }
   return jsonString;
 }
예제 #22
0
 @When("^I fill the form with data from json and submit$")
 public void i_fill_the_form_with_data_from_json_and_submit() throws Throwable {
   JsonParser parser = new JsonParser();
   JsonObject myobject = (JsonObject) parser.parse(json);
   JsonArray myarray = myobject.get("table").getAsJsonArray();
   JsonObject pradeep = myarray.get(0).getAsJsonObject();
   driver.findElement(By.name("firstname")).sendKeys(pradeep.get("firstname").getAsString());
   driver.findElement(By.name("lastname")).sendKeys(pradeep.get("lastname").getAsString());
   driver.findElement(By.id("sex-1")).click();
   driver.findElement(By.id("exp-2")).click();
   driver.findElement(By.id("datepicker")).sendKeys(pradeep.get("date_stopped").getAsString());
   driver.findElement(By.id("tea3")).click();
   driver.findElement(By.id("tool-1")).click();
   Select continents_select = new Select(driver.findElement(By.id("continents")));
   continents_select.selectByVisibleText(pradeep.get("continent").getAsString());
   Select another_select_list = new Select(driver.findElement(By.id("selenium_commands")));
   another_select_list.selectByVisibleText(pradeep.get("selenium_commands").getAsString());
   driver.findElement(By.id("submit")).click();
   AssertJUnit.assertEquals("Welcome", driver.getTitle());
 }
 protected final double _testRawDeser(int reps, byte[] json, ObjectReader reader)
     throws IOException {
   long start = System.nanoTime();
   final JsonFactory f = reader.getFactory();
   while (--reps >= 0) {
     JsonParser p = f.createParser(new ByteArrayInputStream(json));
     JsonToken t;
     while ((t = p.nextToken()) != null) {
       if (t == JsonToken.VALUE_STRING) {
         p.getText();
       } else if (t.isNumeric()) {
         p.getNumberValue();
       }
       ;
     }
     p.close();
   }
   hash = f.hashCode();
   return _msecsFromNanos(System.nanoTime() - start);
 }
예제 #24
0
 protected Object _unwrapAndDeserialize(
     JsonParser jp, DeserializationContext ctxt, JavaType rootType, JsonDeserializer<Object> deser)
     throws IOException, JsonParseException, JsonMappingException {
   SerializedString rootName = _provider.findExpectedRootName(ctxt.getConfig(), rootType);
   if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
     throw JsonMappingException.from(
         jp,
         "Current token not START_OBJECT (needed to unwrap root name '"
             + rootName
             + "'), but "
             + jp.getCurrentToken());
   }
   if (jp.nextToken() != JsonToken.FIELD_NAME) {
     throw JsonMappingException.from(
         jp,
         "Current token not FIELD_NAME (to contain expected root name '"
             + rootName
             + "'), but "
             + jp.getCurrentToken());
   }
   String actualName = jp.getCurrentName();
   if (!rootName.getValue().equals(actualName)) {
     throw JsonMappingException.from(
         jp,
         "Root name '"
             + actualName
             + "' does not match expected ('"
             + rootName
             + "') for type "
             + rootType);
   }
   // ok, then move to value itself....
   jp.nextToken();
   Object result;
   if (_valueToUpdate == null) {
     result = deser.deserialize(jp, ctxt);
   } else {
     deser.deserialize(jp, ctxt, _valueToUpdate);
     result = _valueToUpdate;
   }
   // and last, verify that we now get matching END_OBJECT
   if (jp.nextToken() != JsonToken.END_OBJECT) {
     throw JsonMappingException.from(
         jp,
         "Current token not END_OBJECT (to match wrapper object with root name '"
             + rootName
             + "'), but "
             + jp.getCurrentToken());
   }
   return result;
 }
 public void testSimpleArrayWrite() throws Exception {
   StringWriter sw = new StringWriter();
   JsonGenerator gen = new JsonFactory().createGenerator(sw);
   gen.writeStartArray();
   gen.writeNumber(13);
   gen.writeBoolean(true);
   gen.writeString("foobar");
   gen.writeEndArray();
   gen.close();
   String docStr = sw.toString();
   JsonParser jp = createParserUsingReader(docStr);
   assertEquals(JsonToken.START_ARRAY, jp.nextToken());
   assertEquals(JsonToken.VALUE_NUMBER_INT, jp.nextToken());
   assertEquals(13, jp.getIntValue());
   assertEquals(JsonToken.VALUE_TRUE, jp.nextToken());
   assertEquals(JsonToken.VALUE_STRING, jp.nextToken());
   assertEquals("foobar", jp.getText());
   assertEquals(JsonToken.END_ARRAY, jp.nextToken());
   assertEquals(null, jp.nextToken());
   jp.close();
 }
예제 #26
0
 private int getTotalBuilds(CIJob job) throws PhrescoException {
   try {
     S_LOGGER.debug("Entering Method CIManagerImpl.getTotalBuilds(CIJob job)");
     S_LOGGER.debug("getCIBuilds()  JobName = " + job.getName());
     JsonArray jsonArray = getBuildsArray(job);
     Gson gson = new Gson();
     CIBuild ciBuild = null;
     if (jsonArray.size() > 0) {
       ciBuild = gson.fromJson(jsonArray.get(0), CIBuild.class);
       String buildUrl = ciBuild.getUrl();
       String jenkinsUrl = job.getJenkinsUrl() + ":" + job.getJenkinsPort();
       // display the jenkins running url in ci
       buildUrl = buildUrl.replaceAll("localhost:" + job.getJenkinsPort(), jenkinsUrl);
       // list
       String response = getJsonResponse(buildUrl + API_JSON);
       JsonParser parser = new JsonParser();
       JsonElement jsonElement = parser.parse(response);
       JsonObject jsonObject = jsonElement.getAsJsonObject();
       JsonElement resultJson = jsonObject.get(FrameworkConstants.CI_JOB_BUILD_RESULT);
       JsonArray asJsonArray =
           jsonObject.getAsJsonArray(FrameworkConstants.CI_JOB_BUILD_ARTIFACTS);
       // when build result is not known
       if (jsonObject.get(FrameworkConstants.CI_JOB_BUILD_RESULT).toString().equals(STRING_NULL)) {
         // it indicates the job is in progress and not yet completed
         return -1;
         // when build is success and build zip relative path is unknown
       } else if (resultJson.getAsString().equals(CI_SUCCESS_FLAG) && asJsonArray.size() < 1) {
         return -1;
       } else {
         return jsonArray.size();
       }
     } else {
       return -1; // When the project is build first time,
     }
   } catch (ClientHandlerException ex) {
     S_LOGGER.error(ex.getLocalizedMessage());
     throw new PhrescoException(ex);
   }
 }
예제 #27
0
 protected Object _bindAndClose(JsonParser jp)
     throws IOException, JsonParseException, JsonMappingException {
   if (_schema != null) {
     jp.setSchema(_schema);
   }
   try {
     Object result;
     JsonToken t = _initForReading(jp);
     if (t == JsonToken.VALUE_NULL) {
       if (_valueToUpdate == null) {
         result = _findRootDeserializer(_config, _valueType).getNullValue();
       } else {
         result = _valueToUpdate;
       }
     } else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
       result = _valueToUpdate;
     } else {
       DeserializationContext ctxt = _createDeserializationContext(jp, _config);
       JsonDeserializer<Object> deser = _findRootDeserializer(_config, _valueType);
       if (_unwrapRoot) {
         result = _unwrapAndDeserialize(jp, ctxt, _valueType, deser);
       } else {
         if (_valueToUpdate == null) {
           result = deser.deserialize(jp, ctxt);
         } else {
           deser.deserialize(jp, ctxt, _valueToUpdate);
           result = _valueToUpdate;
         }
       }
     }
     return result;
   } finally {
     try {
       jp.close();
     } catch (IOException ioe) {
     }
   }
 }
예제 #28
0
 protected JsonNode _bindAsTree(JsonParser jp)
     throws IOException, JsonParseException, JsonMappingException {
   JsonNode result;
   JsonToken t = _initForReading(jp);
   if (t == JsonToken.VALUE_NULL || t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
     result = NullNode.instance;
   } else {
     DeserializationContext ctxt = _createDeserializationContext(jp, _config);
     JsonDeserializer<Object> deser = _findRootDeserializer(_config, JSON_NODE_TYPE);
     if (_unwrapRoot) {
       result = (JsonNode) _unwrapAndDeserialize(jp, ctxt, JSON_NODE_TYPE, deser);
     } else {
       result = (JsonNode) deser.deserialize(jp, ctxt);
     }
   }
   // Need to consume the token too
   jp.clearCurrentToken();
   return result;
 }
  protected MediaContent readMediaContent(JsonParser parser) throws IOException {
    MediaContent mc = new MediaContent();
    if (parser.nextToken() != JsonToken.START_OBJECT) {
      reportIllegal(parser, JsonToken.START_OBJECT);
    }
    // first fast version when field-order is as expected
    if (parser.nextFieldName(FIELD_MEDIA)) {
      mc.media = readMedia(parser);
      if (parser.nextFieldName(FIELD_IMAGES)) {
        mc.images = readImages(parser);
        parser.nextToken();
        verifyCurrent(parser, JsonToken.END_OBJECT);
        return mc;
      }
    }

    // and fallback if order was changed
    for (; parser.getCurrentToken() == JsonToken.FIELD_NAME; parser.nextToken()) {
      String field = parser.getCurrentName();
      Integer I = fullFieldToIndex.get(field);
      if (I != null) {
        switch (I) {
          case FIELD_IX_MEDIA:
            mc.media = readMedia(parser);
            continue;
          case FIELD_IX_IMAGES:
            mc.images = readImages(parser);
            continue;
        }
      }
      throw new IllegalStateException("Unexpected field '" + field + "'");
    }
    verifyCurrent(parser, JsonToken.END_OBJECT);

    if (mc.media == null) throw new IllegalStateException("Missing field: " + FIELD_MEDIA);
    if (mc.images == null) mc.images = new ArrayList<Image>();

    return mc;
  }
 private final void verifyCurrent(JsonParser parser, JsonToken expToken) throws IOException {
   if (parser.getCurrentToken() != expToken) {
     reportIllegal(parser, expToken);
   }
 }