Ejemplo n.º 1
0
 {
     jsonparser = ((JsonParser) (jsonparser.getEmbeddedObject()));
     if (jsonparser == null)
     {
         return null;
     }
     if (jsonparser instanceof byte[])
     {
         return Base64Variants.getDefaultVariant().encode((byte[])(byte[])jsonparser, false);
     } else
     {
         return jsonparser.toString();
     }
 }
 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);
 }
Ejemplo n.º 3
0
 @Override
 public String deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   // 22-Sep-2012, tatu: For 2.1, use this new method, may force coercion:
   String text = jp.getValueAsString();
   if (text != null) {
     return text;
   }
   // [JACKSON-330]: need to gracefully handle byte[] data, as base64
   JsonToken curr = jp.getCurrentToken();
   if (curr == JsonToken.VALUE_EMBEDDED_OBJECT) {
     Object ob = jp.getEmbeddedObject();
     if (ob == null) {
       return null;
     }
     if (ob instanceof byte[]) {
       return Base64Variants.getDefaultVariant().encode((byte[]) ob, false);
     }
     // otherwise, try conversion using toString()...
     return ob.toString();
   }
   throw ctxt.mappingException(_valueClass, curr);
 }