Beispiel #1
0
 @Override
 public void convertValue(
     final ValueConversionContext conversionContext,
     final Object value,
     final JavaTypeInfo<?> type) {
   if (type.getRawClass() == ViewClientKey.class) {
     final ViewClientHandle viewClient = (ViewClientHandle) value;
     conversionContext.setResult(viewClient.get().getViewClientKey());
     viewClient.unlock();
   } else {
     final ViewClientKey key = (ViewClientKey) value;
     conversionContext.setResult(
         conversionContext.getUserContext().getViewClients().lockViewClient(key));
   }
 }
 @Override
 public void convertValue(
     final ValueConversionContext conversionContext,
     final Object value,
     final JavaTypeInfo<?> type) {
   if ((value == null) && type.isAllowNull()) {
     conversionContext.setResult(null);
     return;
   }
   final Class<?> clazz = type.getRawClass();
   if (clazz == Value.class) {
     if (value instanceof LocalDate) {
       conversionContext.setResult(ValueUtils.of(((LocalDate) value).toString()));
     } else if (value instanceof InstantProvider) {
       conversionContext.setResult(
           ValueUtils.of((double) ((InstantProvider) value).toInstant().getEpochSeconds()));
     } else {
       conversionContext.setFail();
     }
   } else if (clazz == LocalDate.class) {
     final String str = ((Value) value).getStringValue();
     if (str != null) {
       try {
         conversionContext.setResult(LocalDate.parse(str));
       } catch (CalendricalException e) {
         conversionContext.setFail();
       }
     } else {
       conversionContext.setFail();
     }
   } else if (clazz == Instant.class) {
     final Double epochSeconds = ((Value) value).getDoubleValue();
     if (epochSeconds != null) {
       conversionContext.setResult(Instant.ofEpochSeconds(epochSeconds.longValue()));
     } else {
       conversionContext.setFail();
     }
   } else if (clazz == ZonedDateTime.class) {
     final ZonedDateTime zdt = valueToZonedDateTime((Value) value);
     if (zdt != null) {
       conversionContext.setResult(zdt);
     } else {
       conversionContext.setFail();
     }
   } else if (clazz == Expiry.class) {
     final ZonedDateTime zdt = valueToZonedDateTime((Value) value);
     if (zdt != null) {
       conversionContext.setResult(new Expiry(zdt));
     } else {
       conversionContext.setFail();
     }
   } else {
     conversionContext.setFail();
   }
 }