@Override
 public void appendTo(JsonGenerator generator) throws IOException {
   generator.writeStartArray();
   generator.writeString(this.bucket);
   generator.writeString(this.key);
   appendKeyData(generator);
   generator.writeEndArray();
 }
 @Override
 public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   if (value == null) {
     jgen.writeString("");
   }
   jgen.writeString(new SimpleDateFormat("yyyy-MM-dd HH:mm:SS").format(value));
 }
Пример #3
0
  void toJson(JsonGenerator gen) throws IOException {
    gen.writeStartObject();
    gen.writeArrayFieldStart("sourceSchemas");
    for (Schema schema : schemas) {
      schema.toJson(gen);
    }
    gen.writeEndArray();
    gen.writeObjectFieldStart("fieldAliases");
    for (Map.Entry<String, Map<String, String>> entry : schemaFieldAliases.entrySet()) {
      String schemaName = entry.getKey();
      Map<String, String> aliases = entry.getValue();
      gen.writeObjectField(schemaName, aliases);
    }
    gen.writeEndObject();

    gen.writeArrayFieldStart("groupByFields");
    for (String field : groupByFields) {
      gen.writeString(field);
    }
    gen.writeEndArray();

    if (customPartitionFields != null && !customPartitionFields.isEmpty()) {
      gen.writeArrayFieldStart("customPartitionFields");
      for (String field : customPartitionFields) {
        gen.writeString(field);
      }
      gen.writeEndArray();
    }

    if (rollupFrom != null) {
      gen.writeFieldName("rollupFrom");
      gen.writeString(rollupFrom);
    }

    gen.writeFieldName("commonOrderBy");
    commonCriteria.toJson(gen);

    gen.writeStringField("schemasOrder", schemasOrder.toString());

    // TODO this code should write a map with sourceName
    if (specificCriterias == null || specificCriterias.isEmpty()) {
      initSecondaryCriteriasWithNull();
    }
    gen.writeArrayFieldStart("specificOrderBys");
    for (Criteria c : specificCriterias) {
      if (c == null) {
        gen.writeNull();
      } else {
        c.toJson(gen);
      }
    }
    gen.writeEndArray();
    gen.writeEndObject();
  }
 @Override
 public void serialize(
     final RegisterMessage register, final JsonGenerator jgen, final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(RegisterMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(register.getMessageType().toString().toLowerCase());
   jgen.writeFieldName(RegisterMessage.CHANNEL_ID_FIELD);
   jgen.writeString(register.getChannelId());
   jgen.writeEndObject();
 }
  public void jacksonTest() throws Exception {
    JsonFactory factory = new JsonFactory();
    StringWriter writer = new StringWriter();
    JsonGenerator generator = factory.createJsonGenerator(writer);
    generator.writeStartObject();
    generator.writeFieldName("bool");
    generator.writeBoolean(true);
    generator.writeFieldName("firstName");
    generator.writeString("john");
    generator.writeFieldName("age");
    generator.writeNumber(1);
    generator.writeFieldName("gg");
    generator.writeStartObject();
    generator.writeFieldName("firstName");
    generator.writeString("john");
    generator.writeEndObject();

    generator.writeEndObject();
    generator.close();
    String generated = writer.toString();
    System.out.print(generated);

    JsonParser parser = factory.createJsonParser(generated);
    assertTrue(parser.nextToken() == JsonToken.START_OBJECT);
    parser.nextToken();

    assertEquals("bool", parser.getCurrentName());
    assertTrue(parser.nextToken() == JsonToken.VALUE_TRUE);
    parser.nextToken();

    assertEquals("firstName", parser.getCurrentName());
    parser.nextToken();
    assertEquals("john", parser.getText());
    parser.nextToken();

    assertEquals("age", parser.getCurrentName());
    parser.nextToken();
    assertTrue(1 == parser.getIntValue());
    parser.nextToken();

    assertEquals("gg", parser.getCurrentName());
    assertTrue(parser.nextToken() == JsonToken.START_OBJECT);
    parser.nextToken();
    assertEquals("firstName", parser.getCurrentName());
    parser.nextToken();
    assertEquals("john", parser.getText());
    assertTrue(parser.nextToken() == JsonToken.END_OBJECT);

    assertTrue(parser.nextToken() == JsonToken.END_OBJECT);

    parser.close();
  }
 @Override
 public void serialize(
     final HelloResponse helloResponse,
     final JsonGenerator jgen,
     final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(HelloMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(helloResponse.getMessageType().toString().toLowerCase());
   jgen.writeFieldName(HelloMessage.UAID_FIELD);
   jgen.writeString(helloResponse.getUAID().toString());
   jgen.writeEndObject();
 }
 @Override
 public void serialize(
     final UnregisterResponse unregisterResponse,
     final JsonGenerator jgen,
     final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(RegisterResponse.MESSSAGE_TYPE_FIELD);
   jgen.writeString(unregisterResponse.getMessageType().toString().toLowerCase());
   jgen.writeFieldName(RegisterResponse.CHANNEL_ID_FIELD);
   jgen.writeString(unregisterResponse.getChannelId());
   jgen.writeFieldName(RegisterResponse.STATUS_FIELD);
   jgen.writeNumber(unregisterResponse.getStatus().getCode());
   jgen.writeEndObject();
 }
 @Override
 public void serialize(
     final HelloMessage hello, final JsonGenerator jgen, final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(HelloMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(hello.getMessageType().toString().toLowerCase());
   jgen.writeFieldName(HelloMessage.UAID_FIELD);
   jgen.writeString(hello.getUAID());
   jgen.writeArrayFieldStart(HelloMessage.CHANNEL_IDS_FIELD);
   for (String channelId : hello.getChannelIds()) {
     jgen.writeString(channelId);
   }
   jgen.writeEndArray();
   jgen.writeEndObject();
 }
Пример #9
0
    public void toJson(JsonGenerator gen) throws IOException {
      gen.writeStartObject();

      gen.writeBooleanField("old", oldRecordExists);
      gen.writeBooleanField("new", newRecordExists);
      gen.writeBooleanField("includeSubscriptions", includeSubscriptions);

      if (newRecordType != null) {
        gen.writeBinaryField("newRecordType", newRecordType.getBytes());
      }

      if (oldRecordType != null) {
        gen.writeBinaryField("oldRecordType", oldRecordType.getBytes());
      }

      if (fieldChanges != null) {
        gen.writeArrayFieldStart("fields");

        for (FieldChange fieldChange : fieldChanges) {
          fieldChange.toJson(gen);
        }

        gen.writeEndArray();
      }

      if (indexSubscriptionIds != null) {
        gen.writeArrayFieldStart("subscriptions");
        for (String subscriptionId : indexSubscriptionIds) {
          gen.writeString(subscriptionId);
        }
        gen.writeEndArray();
      }

      gen.writeEndObject();
    }
Пример #10
0
  public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)
      throws IOException, JsonProcessingException {

    String formattedDate = dateFormat.format(date);

    gen.writeString(formattedDate);
  }
 @Override
 public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   String formattedDate = formatter.format(value);
   jgen.writeString(formattedDate);
 }
 /*    */ public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
     /*    */ throws IOException, JsonProcessingException
       /*    */ {
   /* 20 */ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
   /* 21 */ String formattedDate = formatter.format(value);
   /* 22 */ jgen.writeString(formattedDate);
   /*    */ }
 /**
  * Implementation of serialize json content into the value type.
  *
  * @param value value Object
  * @param jgen json generator
  * @param provider serializer provider
  * @throws IOException when IO exception occurred
  * @throws JsonProcessingException when json processing exception occurred
  */
 @Override
 public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeString(
       (String)
           this.conversionService.convert(
               value, sourceType, TypeDescriptor.valueOf(String.class)));
 }
 @Override
 public void serialize(Calendar arg0, JsonGenerator arg1, SerializerProvider arg2)
     throws IOException, JsonProcessingException {
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
   // try {
   String format = formatter.format(arg0.getTime());
   arg1.writeString(format);
   // } catch(IllegalArgumentException e) { throw new IllegalArgumentException(arg0.toString(),); }
 }
  @Override
  public void serialize(Date date, JsonGenerator generator, SerializerProvider peovider)
      throws IOException, JsonProcessingException {

    SimpleDateFormat dateFormat = new SimpleDateFormat(PATTER);

    String dateString = dateFormat.format(date);
    generator.writeString(dateString);
  }
Пример #16
0
 @Override
 public void serialize(
     final AckMessage ack, final JsonGenerator jgen, final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(AckMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(ack.getMessageType().toString().toLowerCase());
   jgen.writeArrayFieldStart(AckMessage.UPDATES_FIELD);
   for (Update update : ack.getUpdates()) {
     jgen.writeStartObject();
     jgen.writeFieldName("channelID");
     jgen.writeString(update.getChannelId());
     jgen.writeFieldName(AckMessage.VERSION_FIELD);
     jgen.writeNumber(update.getVersion());
     jgen.writeEndObject();
   }
   jgen.writeEndArray();
   jgen.writeEndObject();
 }
  @Override
  public void serialize(
      PROPERTY_VALUE property_value,
      JsonGenerator jsonGenerator,
      SerializerProvider serializerProvider)
      throws IOException, JsonProcessingException {

    jsonGenerator.writeStartObject();
    jsonGenerator.writeFieldName(property_value.getKey());
    jsonGenerator.writeString(property_value.getValue());
    jsonGenerator.writeEndObject();
  }
Пример #18
0
 @Override
 public void serialize(
     final NotificationMessage notification,
     final JsonGenerator jgen,
     final SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeStartObject();
   jgen.writeFieldName(NotificationMessage.MESSSAGE_TYPE_FIELD);
   jgen.writeString(notification.getMessageType().toString().toLowerCase());
   jgen.writeArrayFieldStart(NotificationMessage.UPDATES_FIELD);
   for (Update update : notification.getUpdates()) {
     jgen.writeStartObject();
     jgen.writeFieldName(RegisterMessage.CHANNEL_ID_FIELD);
     jgen.writeString(update.getChannelId());
     jgen.writeFieldName(NotificationMessage.VERSION_FIELD);
     jgen.writeNumber(update.getVersion());
     jgen.writeEndObject();
   }
   jgen.writeEndArray();
   jgen.writeEndObject();
 }
Пример #19
0
  @Override
  public void serialize(HateoasLinkList value, JsonGenerator jgen, SerializerProvider provider)
      throws IOException {
    jgen.writeStartObject();

    for (HateoasLink link : value) {
      jgen.writeFieldName(link.rel);
      jgen.writeStartObject();
      jgen.writeFieldName("href");
      jgen.writeString(link.href.toExternalForm());
      jgen.writeEndObject();
    }
    jgen.writeEndObject();
  }
Пример #20
0
 private void writeErrors() throws IOException {
   if (errors != null && !errors.isEmpty()) {
     Writer errorWriter = context.getErrorWriter();
     if (errorWriter != null && errorWriter != context.getWriter()) {
       for (Throwable th : errors) {
         errorWriter.write(Lib.exceptionToString(th));
       }
     } else {
       writer.writeArrayFieldStart("errors");
       for (Throwable th : errors) {
         writer.writeString(Lib.exceptionToString(th));
       }
       writer.writeEndArray();
     }
   }
 }
Пример #21
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));
   }
 }
Пример #22
0
 private void writeScriptData(OrcsScript model) throws IOException {
   Map<String, Object> binding = OrcsScriptUtil.getBinding(model);
   if (binding != null && !binding.isEmpty()) {
     writer.writeFieldName("parameters");
     writer.writeStartObject();
     for (Entry<String, Object> entry : binding.entrySet()) {
       writer.writeStringField(entry.getKey(), String.valueOf(entry.getValue()));
     }
     writer.writeEndObject();
   }
   writer.writeFieldName("script");
   String value = "N/A";
   try {
     if (model != null && model.eAllContents().hasNext()) {
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       OrcsScriptUtil.saveModel(
           model, "orcs:/unknown.orcs", outputStream, OsStorageOption.NO_VALIDATION_ON_SAVE);
       value = outputStream.toString("UTF-8");
     }
   } catch (Exception ex) {
     value = ex.getMessage();
   }
   writer.writeString(value);
 }
Пример #23
0
 @Override
 public void serialize(
     BigInteger value, org.codehaus.jackson.JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeString(value.toString());
 }
Пример #24
0
 @Override
 public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeString(DateFormatUtils.format(value, DATE_FORMAT));
 }
Пример #25
0
 @Override
 public void serialize(GroupExtId value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeString(value.getId());
 }
Пример #26
0
 @Override
 public void serialize(
     Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
     throws IOException, JsonProcessingException {
   jsonGenerator.writeString(DateUtil.format(date));
 }
 @Override
 public void serialize(DateTime dateTime, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeString(DateTimeUtil.toStringISODateTime(dateTime));
 }
Пример #28
0
 @Override
 public void serialize(AmplifierType value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   jgen.writeString(value.toString());
 }
Пример #29
0
 @Override
 public void serialize(
     Sprint sprint, JsonGenerator generator, SerializerProvider serializerProvider)
     throws IOException, JsonProcessingException {
   generator.writeString(sprint.getId().toString());
 }