/**
   * Method that gets textual contents of the current token using available methods, and ensures
   * results are consistent, before returning them
   */
  protected String getAndVerifyText(JsonParser jp) throws IOException, JsonParseException {
    // Ok, let's verify other accessors
    int actLen = jp.getTextLength();
    char[] ch = jp.getTextCharacters();
    String str2 = new String(ch, jp.getTextOffset(), actLen);
    String str = jp.getText();

    if (str.length() != actLen) {
      fail(
          "Internal problem (jp.token == "
              + jp.getCurrentToken()
              + "): jp.getText().length() ['"
              + str
              + "'] == "
              + str.length()
              + "; jp.getTextLength() == "
              + actLen);
    }
    assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);

    return str;
  }
예제 #2
0
 public final void copyCurrentEvent(JsonParser jp) throws IOException, JsonProcessingException {
   switch (jp.getCurrentToken()) {
     case START_OBJECT:
       writeStartObject();
       break;
     case END_OBJECT:
       writeEndObject();
       break;
     case START_ARRAY:
       writeStartArray();
       break;
     case END_ARRAY:
       writeEndArray();
       break;
     case FIELD_NAME:
       writeFieldName(jp.getCurrentName());
       break;
     case VALUE_STRING:
       if (jp.hasTextCharacters()) {
         writeString(jp.getTextCharacters(), jp.getTextOffset(), jp.getTextLength());
       } else {
         writeString(jp.getText());
       }
       break;
     case VALUE_NUMBER_INT:
       switch (jp.getNumberType()) {
         case INT:
           writeNumber(jp.getIntValue());
           break;
         case BIG_INTEGER:
           writeNumber(jp.getBigIntegerValue());
           break;
         default:
           writeNumber(jp.getLongValue());
       }
       break;
     case VALUE_NUMBER_FLOAT:
       switch (jp.getNumberType()) {
         case BIG_DECIMAL:
           writeNumber(jp.getDecimalValue());
           break;
         case FLOAT:
           writeNumber(jp.getFloatValue());
           break;
         default:
           writeNumber(jp.getDoubleValue());
       }
       break;
     case VALUE_TRUE:
       writeBoolean(true);
       break;
     case VALUE_FALSE:
       writeBoolean(false);
       break;
     case VALUE_NULL:
       writeNull();
       break;
     case VALUE_EMBEDDED_OBJECT:
       writeObject(jp.getEmbeddedObject());
       break;
     default:
       _cantHappen();
   }
 }