@Override
  public JType apply(String nodeName, JsonNode node, JsonNode parent, JClassContainer jClassContainer, Schema schema) {

    String propertyTypeName = getTypeName(node);

    JType type;

    if (propertyTypeName.equals("object") || node.has("properties") && node.path("properties").size() > 0) {

      type = ruleFactory.getObjectRule().apply(nodeName, node, parent, jClassContainer.getPackage(), schema);
    } else if (node.has("existingJavaType")) {
      String typeName = node.path("existingJavaType").asText();

      if (isPrimitive(typeName, jClassContainer.owner())) {
        type = primitiveType(typeName, jClassContainer.owner());
      } else {
        type = resolveType(jClassContainer, typeName);
      }
    } else if (propertyTypeName.equals("string")) {

      type = jClassContainer.owner().ref(String.class);
    } else if (propertyTypeName.equals("number")) {

      type = getNumberType(jClassContainer.owner(), ruleFactory.getGenerationConfig());
    } else if (propertyTypeName.equals("integer")) {

      type = getIntegerType(jClassContainer.owner(), node, ruleFactory.getGenerationConfig());
    } else if (propertyTypeName.equals("boolean")) {

      type = unboxIfNecessary(jClassContainer.owner().ref(Boolean.class), ruleFactory.getGenerationConfig());
    } else if (propertyTypeName.equals("array")) {

      type = ruleFactory.getArrayRule().apply(nodeName, node, parent, jClassContainer.getPackage(), schema);
    } else {

      type = jClassContainer.owner().ref(Object.class);
    }

    if (!node.has("javaType") && !node.has("existingJavaType") && node.has("format")) {
      type = ruleFactory.getFormatRule().apply(nodeName, node.get("format"), node, type, schema);
    } else if (!node.has("javaType") && !node.has("existingJavaType") && propertyTypeName.equals("string") && node.has("media")) {
      type = ruleFactory.getMediaRule().apply(nodeName, node.get("media"), node, type, schema);
    }

    return type;
  }
@Test
    public void applyGeneratesArray() {

        JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());

        ObjectNode objectNode = new ObjectMapper().createObjectNode();
        objectNode.put("type", "array");

        JClass mockArrayType = mock(JClass.class);
        ArrayRule mockArrayRule = mock(ArrayRule.class);
        when(mockArrayRule.apply("fooBar", objectNode, null, jpackage, null)).thenReturn(mockArrayType);
        when(ruleFactory.getArrayRule()).thenReturn(mockArrayRule);

        JType result = rule.apply("fooBar", objectNode, null, jpackage, null);

        assertThat(result, is(mockArrayType));
    }