Ejemplo n.º 1
0
  public void toJson(JsonGenerator gen) throws IOException {

    gen.writeStartObject();

    if (type != null) {
      gen.writeStringField("type", type.getName());
    }

    if (tableName != null) {
      gen.writeStringField("tableName", tableName);
    }

    if (versionUpdated != -1) {
      gen.writeNumberField("versionUpdated", versionUpdated);
    }

    if (versionCreated != -1) {
      gen.writeNumberField("versionCreated", versionCreated);
    }

    if (recordTypeChanged) {
      gen.writeBooleanField("recordTypeChanged", true);
    }

    if (updatedFields != null && updatedFields.size() > 0) {
      gen.writeArrayFieldStart("updatedFields");
      for (SchemaId updatedField : updatedFields) {
        gen.writeBinary(updatedField.getBytes());
      }
      gen.writeEndArray();
    }

    if (vtagsToIndex != null && vtagsToIndex.size() > 0) {
      gen.writeArrayFieldStart("vtagsToIndex");
      for (SchemaId vtag : vtagsToIndex) {
        gen.writeBinary(vtag.getBytes());
      }
      gen.writeEndArray();
    }

    if (attributes != null && attributes.size() > 0) {
      gen.writeObjectFieldStart("attributes");
      for (String key : attributes.keySet()) {
        gen.writeStringField(key, attributes.get(key));
      }
      gen.writeEndObject();
    }

    if (indexRecordFilterData != null) {
      gen.writeFieldName("indexFilterData");
      indexRecordFilterData.toJson(gen);
    }

    gen.writeEndObject();
    gen.flush();
  }
Ejemplo n.º 2
0
 @Override
 public void serialize(DataProxy proxy, JsonGenerator writer, SerializerProvider provider)
     throws IOException, JsonGenerationException {
   if (proxy instanceof CharacterDataProxy) {
     CharacterDataProxy characters = (CharacterDataProxy) proxy;
     writer.writeObject(characters.getValueAsString());
   } else if (proxy instanceof BinaryDataProxy) {
     BinaryDataProxy binary = (BinaryDataProxy) proxy;
     ByteBuffer buffer = binary.getValueAsBytes();
     InputStream inputStream = null;
     try {
       inputStream = Lib.byteBufferToInputStream(buffer);
       writer.writeBinary(Lib.inputStreamToBytes(inputStream));
     } finally {
       Lib.close(inputStream);
     }
   }
 }
Ejemplo n.º 3
0
 private void writeScalarPropertyValue(JsonGenerator jg, Type type, Object value)
     throws IOException {
   if (value == null) {
     jg.writeNull();
   } else if (type instanceof BooleanType) {
     jg.writeBoolean((Boolean) value);
   } else if (type instanceof LongType) {
     jg.writeNumber((Long) value);
   } else if (type instanceof DoubleType) {
     jg.writeNumber((Double) value);
   } else if (type instanceof IntegerType) {
     jg.writeNumber((Integer) value);
   } else if (type instanceof BinaryType) {
     jg.writeBinary((byte[]) value);
   } else {
     jg.writeString(type.encode(value));
   }
 }