Exemplo n.º 1
0
 @Override
 public Date deserialize(
     final JsonParser jsonParser, final DeserializationContext deserializationContext)
     throws IOException {
   final JsonToken token = jsonParser.getCurrentToken();
   switch (token) {
     case VALUE_NUMBER_FLOAT:
       return new Date(jsonParser.getDecimalValue().movePointRight(3).longValue());
     case VALUE_NUMBER_INT:
       return new Date(jsonParser.getLongValue() * 1000L);
     default:
       return new DateDeserializers.DateDeserializer()
           .deserialize(jsonParser, deserializationContext);
   }
 }
 /**
  * Method for copying contents of the current event that the given parser instance points to. Note
  * that the method <b>will not</b> copy any other events, such as events contained within Json
  * Array or Object structures.
  *
  * <p>Calling this method will not advance the given parser, although it may cause parser to
  * internally process more data (if it lazy loads contents of value events, for example)
  */
 @Override
 public 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:
       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:
       throw new IllegalStateException();
   }
 }
 /**
  * Default unmarshal for BigDecimal.
  *
  * <p>Used in generated code via static imports method overload resolution by compiler.
  *
  * @param parser the parser
  * @param numberNull the BigDecimal null, always {@code null}
  * @param expectedClass the expected class
  * @return the BigDecimal
  * @throws IOException Signals that an I/O exception has occurred.
  */
 public static BigDecimal unmarshal(
     JsonParser parser, @Nullable BigDecimal numberNull, Class<?> expectedClass)
     throws IOException {
   return parser.getDecimalValue();
 }