コード例 #1
0
 @Override
 public Date read(JsonParser parser) throws IOException, JsonReadException {
   JsonLocation l = parser.getCurrentLocation();
   try {
     char[] buffer = parser.getTextCharacters();
     int offset = parser.getTextOffset();
     int length = parser.getTextLength();
     Date d = parseDropbox8601Date(buffer, offset, length);
     parser.nextToken();
     return d;
   } catch (JsonParseException ex) {
     throw JsonReadException.fromJackson(ex);
   } catch (java.text.ParseException ex) {
     throw new JsonReadException(
         "bad date: \"" + ex.getMessage() + " at offset " + ex.getErrorOffset(), l);
   }
 }
 public char[] deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
 {
   JsonToken localJsonToken1 = paramJsonParser.getCurrentToken();
   if (localJsonToken1 == JsonToken.VALUE_STRING)
   {
     char[] arrayOfChar1 = paramJsonParser.getTextCharacters();
     int i = paramJsonParser.getTextOffset();
     int j = paramJsonParser.getTextLength();
     char[] arrayOfChar2 = new char[j];
     System.arraycopy(arrayOfChar1, i, arrayOfChar2, 0, j);
     return arrayOfChar2;
   }
   if (paramJsonParser.isExpectedStartArrayToken())
   {
     StringBuilder localStringBuilder = new StringBuilder(64);
     while (true)
     {
       JsonToken localJsonToken2 = paramJsonParser.nextToken();
       if (localJsonToken2 == JsonToken.END_ARRAY)
         break;
       if (localJsonToken2 != JsonToken.VALUE_STRING)
         throw paramDeserializationContext.mappingException(Character.TYPE);
       String str = paramJsonParser.getText();
       if (str.length() != 1)
         throw JsonMappingException.from(paramJsonParser, "Can not convert a JSON String of length " + str.length() + " into a char element of char array");
       localStringBuilder.append(str.charAt(0));
     }
     return localStringBuilder.toString().toCharArray();
   }
   if (localJsonToken1 == JsonToken.VALUE_EMBEDDED_OBJECT)
   {
     Object localObject = paramJsonParser.getEmbeddedObject();
     if (localObject == null)
       return null;
     if ((localObject instanceof char[]))
       return (char[])localObject;
     if ((localObject instanceof String))
       return ((String)localObject).toCharArray();
     if ((localObject instanceof byte[]))
       return Base64Variants.getDefaultVariant().encode((byte[])localObject, false).toCharArray();
   }
   throw paramDeserializationContext.mappingException(this._valueClass);
 }
コード例 #3
0
  /**
   * 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;
  }