Exemplo n.º 1
0
 @Override
 public void process(final @NonNull JsonEntity jsonEntity) {
   if (jsonEntity instanceof JsonNull) {
     final byte[] defaultValue = getDefaultValue();
     if (defaultValue != null) {
       this.process(defaultValue);
       return;
     }
     if (allowNull()) {
       this.process((byte[]) null);
       return;
     }
     throw new IllegalArgumentException("Not a JSON number");
   }
   final List<Byte> list = new ArrayList<Byte>();
   if (!(jsonEntity instanceof JsonArray)) throw new IllegalArgumentException("Not a JSON array");
   final JsonArray ja = (JsonArray) jsonEntity;
   for (final JsonEntity je : ja) {
     if (!(je instanceof JsonNumber))
       throw new IllegalArgumentException("Member is not a JSON number");
     final JsonNumber jn = (JsonNumber) je;
     final double value = jn.toDouble();
     if (value < Byte.MIN_VALUE)
       throw new IllegalArgumentException("Member number is out too small");
     if (value > Byte.MAX_VALUE) throw new IllegalArgumentException("Member number is too big");
     list.add(new Byte((byte) value));
   }
   final byte[] bytes = new byte[list.size()];
   int i = 0;
   for (final Byte byteObj : list) bytes[i++] = byteObj.byteValue();
   this.process(bytes);
 }
 @Override
 public @NonNull Datum translate(final BaseUnmarshalledObject buo) {
   final JsonEntity valueJE = buo.getValue();
   if (!(valueJE instanceof JsonNumber)) {
     throw new IllegalArgumentException("Value JsonEntity " + valueJE + " is not a JsonNumber");
   }
   final JsonNumber valueJN = (JsonNumber) valueJE;
   final float value = valueJN.toFloat();
   final Float floatValue = Float.valueOf(value);
   if (floatValue == null) {
     throw new NullPointerException("Impossible Float.valueOf()");
   }
   return new Float4Datum(floatValue, buo.isUnique());
 }