Ejemplo n.º 1
0
    @Override
    public void serialize(ThriftReply value, JsonGenerator gen, SerializerProvider provider)
        throws IOException {
      if (value == null) {
        // Oneway function doesn't provide reply
        gen.writeNull();
        return;
      }

      gen.writeStartObject();

      gen.writeObjectField("header", value.header());

      final TBase<?, ?> result;
      final TApplicationException exception;
      if (value.isException()) {
        result = null;
        exception = value.exception();
      } else {
        result = value.result();
        exception = null;
      }

      gen.writeObjectField("result", result);
      gen.writeObjectField("exception", exception);

      gen.writeEndObject();
    }
Ejemplo n.º 2
0
  @Override
  public void serialize(Item item, JsonGenerator jgen, SerializerProvider provider)
      throws IOException, JsonProcessingException {
    jgen.writeStartArray();

    jgen.writeStartObject();
    jgen.writeStringField("id", "i_" + String.valueOf(item.getId()));
    jgen.writeObjectField("title", item.getName());
    jgen.writeObjectField("type", item.getType());

    String imagePath = "i_image_" + item.getId() + "." + item.getImage().getExtention();

    jgen.writeObjectFieldStart("image");
    jgen.writeObjectField("type", item.getImage().getType());
    jgen.writeObjectField("path", imagePath);
    jgen.writeEndObject();

    jgen.writeObjectFieldStart("values");
    jgen.writeStringField("productName", item.getName());
    jgen.writeStringField("imageFullPath", imagePath);
    for (Description description : item.getDescription()) {
      if (description.getDescription().size() > 1) {
        jgen.writeArrayFieldStart(description.getValue().getKey());
        for (String desc : description.getDescription()) jgen.writeString(desc);
        jgen.writeEndArray();
      } else
        jgen.writeStringField(
            description.getValue().getKey(),
            (description.getDescription().size() == 0) ? "" : description.getDescription().get(0));
    }
    jgen.writeEndObject();

    jgen.writeEndObject();
    jgen.writeEndArray();
  }
  @Override
  public void serialize(IndexInput input, JsonGenerator jg, SerializerProvider sp)
      throws IOException {
    jg.writeStartObject();

    // Riak bug ... explicitly specifying "default" as the type breaks things
    if (!input.getNamespace().getBucketTypeAsString().equals(Namespace.DEFAULT_BUCKET_TYPE)) {
      jg.writeArrayFieldStart("bucket");
      jg.writeString(input.getNamespace().getBucketTypeAsString());
      jg.writeString(input.getNamespace().getBucketNameAsString());
      jg.writeEndArray();
    } else {
      jg.writeStringField("bucket", input.getNamespace().getBucketNameAsString());
    }

    jg.writeStringField("index", input.getIndex());
    IndexInput.IndexCriteria criteria = input.getCriteria();
    if (criteria instanceof IndexInput.MatchCriteria) {
      IndexInput.MatchCriteria<?> match = (IndexInput.MatchCriteria) criteria;
      jg.writeObjectField("key", match.getValue());
    } else if (criteria instanceof IndexInput.RangeCriteria) {
      IndexInput.RangeCriteria range = (IndexInput.RangeCriteria) criteria;
      jg.writeObjectField("start", range.getBegin());
      jg.writeObjectField("end", range.getEnd());
    }
    jg.writeEndObject();
  }
Ejemplo n.º 4
0
    @Override
    public void serialize(
        final GraphSONVertex directionalVertex,
        final JsonGenerator jsonGenerator,
        final SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException {
      final Vertex vertex = directionalVertex.getVertexToSerialize();
      jsonGenerator.writeStartObject();
      jsonGenerator.writeObjectField(GraphSONTokens.ID, vertex.getId());
      jsonGenerator.writeStringField(GraphSONTokens.LABEL, vertex.getLabel());
      jsonGenerator.writeStringField(GraphSONTokens.TYPE, GraphSONTokens.VERTEX);

      if (normalize) {
        jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES);
        vertex
            .getProperties()
            .values()
            .stream()
            .sorted(Comparators.PROPERTY_COMPARATOR)
            .forEachOrdered(
                FunctionUtils.wrapConsumer(
                    e -> jsonGenerator.writeObjectField(e.getKey(), e.get())));
        jsonGenerator.writeEndObject();
      } else {
        jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES);
        vertex
            .getProperties()
            .values()
            .forEach(
                FunctionUtils.wrapConsumer(
                    e -> jsonGenerator.writeObjectField(e.getKey(), e.get())));
        jsonGenerator.writeEndObject();
      }

      if (directionalVertex.getDirection() == Direction.BOTH
          || directionalVertex.getDirection() == Direction.OUT) {
        jsonGenerator.writeArrayFieldStart(GraphSONTokens.OUT);
        if (normalize)
          vertex
              .outE()
              .order(Comparators.HELD_EDGE_COMPARATOR)
              .forEach(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
        else vertex.outE().forEach(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
        jsonGenerator.writeEndArray();
      }

      if (directionalVertex.getDirection() == Direction.BOTH
          || directionalVertex.getDirection() == Direction.IN) {
        jsonGenerator.writeArrayFieldStart(GraphSONTokens.IN);
        if (normalize)
          vertex
              .inE()
              .order(Comparators.HELD_EDGE_COMPARATOR)
              .forEach(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
        else vertex.inE().forEach(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
        jsonGenerator.writeEndArray();
      }
      jsonGenerator.writeEndObject();
    }
Ejemplo n.º 5
0
    @Override
    public void serialize(ThriftCall value, JsonGenerator gen, SerializerProvider provider)
        throws IOException {
      gen.writeStartObject();

      gen.writeObjectField("header", value.header());
      gen.writeObjectField("args", value.args());

      gen.writeEndObject();
    }
 private void writeElement(
     JsonGenerator gen, final String kind, final String reference, final String title)
     throws IOException {
   gen.writeStartObject();
   gen.writeObjectField(Constants.JSON_NAME, title);
   gen.writeObjectField(Constants.JSON_URL, reference);
   if (kind != null) {
     gen.writeObjectField(KIND, kind);
   }
   gen.writeEndObject();
 }
 @Override
 public void serialize(HealthCheck healthCheck, JsonGenerator jgen, SerializerProvider provider)
     throws IOException {
   jgen.writeStartObject();
   jgen.writeNumberField("interval", healthCheck.getInterval());
   jgen.writeStringField("unit", healthCheck.getUnit().toString());
   jgen.writeBooleanField("enabled", healthCheck.isEnabled());
   jgen.writeObjectField("request", healthCheck.getRequest());
   jgen.writeObjectField("expectation", healthCheck.getExpectation());
   jgen.writeEndObject();
 }
Ejemplo n.º 8
0
 @Override
 public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
   gen.writeStartObject();
   gen.writeStringField(ID_FIELD, id);
   gen.writeObjectField(FROM_FIELD, from);
   if (location != null) {
     gen.writeObjectField(LOCATION_FIELD, location);
   }
   gen.writeStringField(QUERY_FIELD, query);
   gen.writeStringField(OFFSET_FIELD, offset);
   gen.writeEndObject();
   gen.flush();
 }
  public void writeServiceDocument(final JsonGenerator gen) throws IOException {
    gen.writeStartObject();

    if (!isODataMetadataNone) {
      final String metadataUri =
          (serviceRoot == null ? "" : serviceRoot.endsWith("/") ? serviceRoot : (serviceRoot + "/"))
              + Constants.METADATA;
      gen.writeObjectField(Constants.JSON_CONTEXT, metadataUri);

      if (metadata != null
          && metadata.getServiceMetadataETagSupport() != null
          && metadata.getServiceMetadataETagSupport().getMetadataETag() != null) {
        gen.writeStringField(
            Constants.JSON_METADATA_ETAG,
            metadata.getServiceMetadataETagSupport().getMetadataETag());
      }
    }

    gen.writeArrayFieldStart(Constants.VALUE);

    final EdmEntityContainer container = metadata.getEdm().getEntityContainer();
    writeEntitySets(gen, container);
    writeFunctionImports(gen, container);
    writeSingletons(gen, container);
  }
 private void _serialise(final HyperLogLogPlus hyperLogLogPlus, final JsonGenerator jsonGenerator)
     throws IOException {
   jsonGenerator.writeObjectFieldStart("hyperLogLogPlus");
   jsonGenerator.writeObjectField(
       HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD,
       hyperLogLogPlus.getBytes());
   jsonGenerator.writeNumberField(
       HyperLogLogPlusJsonConstants.CARDINALITY_FIELD, hyperLogLogPlus.cardinality());
   jsonGenerator.writeEndObject();
 }
 @Override
 public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
   gen.writeStartObject();
   gen.writeStringField(TYPE_FIELD, type);
   gen.writeStringField(ID_FIELD, id);
   gen.writeStringField(GIF_FILE_ID_FIELD, gifFileId);
   if (title != null) {
     gen.writeStringField(TITLE_FIELD, this.title);
   }
   if (caption != null) {
     gen.writeStringField(CAPTION_FIELD, this.caption);
   }
   if (replyMarkup != null) {
     gen.writeObjectField(REPLY_MARKUP_FIELD, replyMarkup);
   }
   if (inputMessageContent != null) {
     gen.writeObjectField(INPUTMESSAGECONTENT_FIELD, inputMessageContent);
   }
   gen.writeEndObject();
   gen.flush();
 }
  @Override
  protected ModelAndView handleRequestInternal(
      final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    String accessToken = request.getParameter(OAuthConstants.ACCESS_TOKEN);
    if (StringUtils.isBlank(accessToken)) {
      final String authHeader = request.getHeader("Authorization");
      if (StringUtils.isNotBlank(authHeader)
          && authHeader.toLowerCase().startsWith(OAuthConstants.BEARER_TOKEN.toLowerCase() + ' ')) {
        accessToken = authHeader.substring(OAuthConstants.BEARER_TOKEN.length() + 1);
      }
    }
    LOGGER.debug("{} : {}", OAuthConstants.ACCESS_TOKEN, accessToken);

    try (final JsonGenerator jsonGenerator =
        this.jsonFactory.createJsonGenerator(response.getWriter())) {
      response.setContentType("application/json");
      // accessToken is required
      if (StringUtils.isBlank(accessToken)) {
        LOGGER.error("Missing {}", OAuthConstants.ACCESS_TOKEN);
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("error", OAuthConstants.MISSING_ACCESS_TOKEN);
        jsonGenerator.writeEndObject();
        return null;
      }
      // get ticket granting ticket
      final TicketGrantingTicket ticketGrantingTicket =
          (TicketGrantingTicket) this.ticketRegistry.getTicket(accessToken);
      if (ticketGrantingTicket == null || ticketGrantingTicket.isExpired()) {
        LOGGER.error("expired accessToken : {}", accessToken);
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("error", OAuthConstants.EXPIRED_ACCESS_TOKEN);
        jsonGenerator.writeEndObject();
        return null;
      }
      // generate profile : identifier + attributes
      final Principal principal = ticketGrantingTicket.getAuthentication().getPrincipal();
      jsonGenerator.writeStartObject();
      jsonGenerator.writeStringField(ID, principal.getId());
      jsonGenerator.writeObjectFieldStart(ATTRIBUTES);
      final Map<String, Object> attributes = principal.getAttributes();
      for (final Map.Entry<String, Object> entry : attributes.entrySet()) {
        //                jsonGenerator.writeStartObject();
        jsonGenerator.writeObjectField(entry.getKey(), entry.getValue());
        //                jsonGenerator.writeEndObject();
      }
      //            jsonGenerator.writeEndArray();
      jsonGenerator.writeEndObject();
      return null;
    } finally {
      response.flushBuffer();
    }
  }
  @Override
  public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
    gen.writeStartObject();
    gen.writeStringField(TYPE_FIELD, type);
    gen.writeStringField(ID_FIELD, id);
    gen.writeStringField(PHOTOURL_FIELD, this.photoUrl);
    if (mimeType != null) {
      gen.writeStringField(MIMETYPE_FIELD, this.mimeType);
    }
    if (photoWidth != null) {
      gen.writeNumberField(PHOTOWIDTH_FIELD, this.photoWidth);
    }
    if (photoHeight != null) {
      gen.writeNumberField(PHOTOHEIGHT_FIELD, this.photoHeight);
    }
    if (thumbUrl != null) {
      gen.writeStringField(THUMBURL_FIELD, this.thumbUrl);
    }
    if (description != null) {
      gen.writeStringField(DESCRIPTION_FIELD, this.description);
    }
    if (title != null) {
      gen.writeStringField(TITLE_FIELD, this.title);
    }
    if (caption != null) {
      gen.writeStringField(CAPTION_FIELD, this.caption);
    }
    if (replyMarkup != null) {
      gen.writeObjectField(REPLY_MARKUP_FIELD, replyMarkup);
    }
    if (inputMessageContent != null) {
      gen.writeObjectField(INPUTMESSAGECONTENT_FIELD, inputMessageContent);
    }

    gen.writeEndObject();
    gen.flush();
  }
Ejemplo n.º 14
0
    @Override
    public void serialize(Record record, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
      jgen.writeStartObject();
      jgen.writeStringField("id", record.getId());
      jgen.writeStringField("type", record.getType());
      jgen.writeStringField("creationDate", record.getTime().toString());

      jgen.writeObjectFieldStart("fields");
      for (Map.Entry<String, Field> entry : record.getFieldsEntrySet()) {
        // retrieve event field
        String fieldName = entry.getKey();
        Field field = entry.getValue();
        Object fieldValue = field.getRawValue();
        String fieldType = field.getType().toString();

        // dump event field as record attribute

        try {
          switch (fieldType.toLowerCase()) {
            case "string":
              jgen.writeStringField(fieldName, (String) fieldValue);
              break;
            case "integer":
              jgen.writeNumberField(fieldName, (int) fieldValue);
              break;
            case "long":
              jgen.writeNumberField(fieldName, (long) fieldValue);
              break;
            case "float":
              jgen.writeNumberField(fieldName, (float) fieldValue);
              break;
            case "double":
              jgen.writeNumberField(fieldName, (double) fieldValue);
              break;
            case "boolean":
              jgen.writeBooleanField(fieldName, (boolean) fieldValue);
              break;
            default:
              jgen.writeObjectField(fieldName, fieldValue);
              break;
          }
        } catch (Exception ex) {
          logger.debug("exception while serializing field {}", field);
        }
      }
      jgen.writeEndObject();
      jgen.writeEndObject();
    }
 @Override
 public void serialize(DataNode dataNode, JsonGenerator generator, SerializerProvider provider)
     throws IOException, JsonProcessingException {
   try {
     generator.writeStartObject();
     for (DictionaryEntry entry : dataNode.getDictionaryEntries()) {
       String childName = entry.getName();
       DataNode childNode = entry.getDataNode();
       generator.writeObjectField(childName, childNode);
     }
     generator.writeEndObject();
   } catch (BigDBException e) {
     assert false;
   }
 }
  @Override
  public void serialize(
      Message message, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
      throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField("messageId", message.getMessageId());
    jsonGenerator.writeStringField("content", message.getContent());
    jsonGenerator.writeStringField("conversationId", message.getConversationId());

    ResourceBundle formatsProperties = ResourceBundle.getBundle("formats", Locale.ENGLISH);
    DateFormat dateFormat =
        new SimpleDateFormat(formatsProperties.getString("dateFormat.postedOn.javaToJson"));

    jsonGenerator.writeStringField("postedOn", dateFormat.format(message.getPostedOn()));
    jsonGenerator.writeObjectField("postedBy", message.getPostedBy());
    jsonGenerator.writeEndObject();
  }
Ejemplo n.º 17
0
 @Override
 public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
   gen.writeStartObject();
   gen.writeStringField(FILEID_FIELD, fileId);
   gen.writeObjectField(THUMB_FIELD, thumb);
   if (fileName != null) {
     gen.writeStringField(FILENAME_FIELD, fileName);
   }
   if (mimeType != null) {
     gen.writeStringField(MIMETYPE_FIELD, mimeType);
   }
   if (fileSize != null) {
     gen.writeNumberField(FILESIZE_FIELD, fileSize);
   }
   gen.writeEndObject();
   gen.flush();
 }
Ejemplo n.º 18
0
 public void toJSON(JsonGenerator json) {
   try {
     json.writeStartObject(); // object name for this should be 'user'
     json.writeObjectField(UserFactory.field_screen_name, getScreenName());
     json.writeObjectField(UserFactory.field_user_id, getUserId());
     json.writeObjectField(UserFactory.field_name, getName());
     if (this.map.containsKey(UserFactory.field_profile_image_url_http))
       json.writeObjectField(
           UserFactory.field_profile_image_url_http,
           this.map.get(UserFactory.field_profile_image_url_http));
     if (this.map.containsKey(UserFactory.field_profile_image_url_https))
       json.writeObjectField(
           UserFactory.field_profile_image_url_https,
           this.map.get(UserFactory.field_profile_image_url_https));
     writeDate(json, UserFactory.field_appearance_first, getAppearanceFirst().getTime());
     writeDate(json, UserFactory.field_appearance_latest, getAppearanceLatest().getTime());
     if (this.map.containsKey(UserFactory.field_profile_image))
       json.writeObjectField(
           UserFactory.field_profile_image, this.map.get(UserFactory.field_profile_image));
     json.writeEndObject();
   } catch (IOException e) {
   }
 }