Ejemplo n.º 1
0
 protected static void parseNested(
     String name, Map<String, Object> node, ObjectMapper.Builder builder) {
   boolean nested = false;
   boolean nestedIncludeInParent = false;
   boolean nestedIncludeInRoot = false;
   Object fieldNode = node.get("type");
   if (fieldNode != null) {
     String type = fieldNode.toString();
     if (type.equals(CONTENT_TYPE)) {
       builder.nested = Nested.NO;
     } else if (type.equals(NESTED_CONTENT_TYPE)) {
       nested = true;
     } else {
       throw new MapperParsingException(
           "Trying to parse an object but has a different type ["
               + type
               + "] for ["
               + name
               + "]");
     }
   }
   fieldNode = node.get("include_in_parent");
   if (fieldNode != null) {
     nestedIncludeInParent = nodeBooleanValue(fieldNode);
     node.remove("include_in_parent");
   }
   fieldNode = node.get("include_in_root");
   if (fieldNode != null) {
     nestedIncludeInRoot = nodeBooleanValue(fieldNode);
     node.remove("include_in_root");
   }
   if (nested) {
     builder.nested = Nested.newNested(nestedIncludeInParent, nestedIncludeInRoot);
   }
 }
Ejemplo n.º 2
0
    @Override
    public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
        throws MapperParsingException {
      Map<String, Object> objectNode = node;
      ObjectMapper.Builder builder = createBuilder(name);

      boolean nested = false;
      boolean nestedIncludeInParent = false;
      boolean nestedIncludeInRoot = false;
      for (Map.Entry<String, Object> entry : objectNode.entrySet()) {
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();

        if (fieldName.equals("dynamic")) {
          String value = fieldNode.toString();
          if (value.equalsIgnoreCase("strict")) {
            builder.dynamic(Dynamic.STRICT);
          } else {
            builder.dynamic(nodeBooleanValue(fieldNode) ? Dynamic.TRUE : Dynamic.FALSE);
          }
        } else if (fieldName.equals("type")) {
          String type = fieldNode.toString();
          if (type.equals(CONTENT_TYPE)) {
            builder.nested = Nested.NO;
          } else if (type.equals(NESTED_CONTENT_TYPE)) {
            nested = true;
          } else {
            throw new MapperParsingException(
                "Trying to parse an object but has a different type ["
                    + type
                    + "] for ["
                    + name
                    + "]");
          }
        } else if (fieldName.equals("include_in_parent")) {
          nestedIncludeInParent = nodeBooleanValue(fieldNode);
        } else if (fieldName.equals("include_in_root")) {
          nestedIncludeInRoot = nodeBooleanValue(fieldNode);
        } else if (fieldName.equals("enabled")) {
          builder.enabled(nodeBooleanValue(fieldNode));
        } else if (fieldName.equals("path")) {
          builder.pathType(parsePathType(name, fieldNode.toString()));
        } else if (fieldName.equals("properties")) {
          parseProperties(builder, (Map<String, Object>) fieldNode, parserContext);
        } else if (fieldName.equals("include_in_all")) {
          builder.includeInAll(nodeBooleanValue(fieldNode));
        } else {
          processField(builder, fieldName, fieldNode);
        }
      }

      if (nested) {
        builder.nested = Nested.newNested(nestedIncludeInParent, nestedIncludeInRoot);
      }

      return builder;
    }