示例#1
0
 public String toJson(ObjectMapper mapper) {
   ObjectNode rootNode = mapper.createObjectNode();
   ArrayNode keysNode = rootNode.putArray("keys");
   for (Object key : keys) {
     keysNode.addPOJO(key);
   }
   try {
     return mapper.writeValueAsString(rootNode);
   } catch (Exception e) {
     throw Exceptions.propagate(e);
   }
 }
  private void handleProperties(
      Map<String, Object> mapToFill,
      ArrayList<Map.Entry<String, JsonNode>> itProperties,
      Object returnedValue)
      throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    for (int k = 0; k < itProperties.size(); k++) {
      String titleBean = itProperties.get(k).getKey();

      FMDProperty objectProperty =
          fillObjectProperty(
              Lists.newArrayList(itProperties.get(k).getValue().fields()).listIterator());
      if (objectProperty.getTitleBean() == null) {
        objectProperty.setTitleBean(titleBean);
      }

      Object mdsdValue = getReturnedValueFromObject(objectProperty, returnedValue, titleBean);

      if (mdsdValue != null) {

        // if there is not a reference
        if (objectProperty.getReference() == null) {
          String orderObj = getOrderFromEntity(objectProperty.getOrder());
          if (isReadyToPut(objectProperty)) {
            Object valueToPut =
                ((((ValueNode) mdsdValue).getNodeType().toString()).equals("NUMBER"))
                    ? mdsdValue
                    : ((TextNode) mdsdValue).asText();
            mapToFill.put(
                orderObj,
                new FMDescriptor(
                    titleBean,
                    objectProperty.getTitleToVisualize(),
                    objectProperty.getDescription(),
                    valueToPut));
          } else if (objectProperty.getType() != null
              && objectProperty.getType().equals(ARRAY_TYPE)
              && objectProperty.getItems().get(TYPE_FIELD) != null
              && objectProperty.getItems().get(TYPE_FIELD).asText().equals(STRING_TYPE)) {
            ArrayNode values = ((ArrayNode) mdsdValue);
            for (int i = 0, size = values.size(); i < size; i++) {
              values.add(values.get(i).textValue());
            }
            mapToFill.put(
                orderObj,
                new FMDescriptor(
                    titleBean,
                    objectProperty.getTitleToVisualize(),
                    objectProperty.getDescription(),
                    values));
          } else {
            mapToFill.put(
                orderObj,
                new FMDescriptor(
                    titleBean,
                    objectProperty.getTitleToVisualize(),
                    objectProperty.getDescription(),
                    fillRecursive2(itProperties.get(k).getValue().fields(), mdsdValue)));
          }
        }
        // if it is a reference
        else {
          handleReferences(
              objectProperty.getReference(), objectProperty, mapToFill, mdsdValue, false);
        }
      }
    }
  }