Search in sources :

Example 1 with NameHelper

use of org.jsonschema2pojo.util.NameHelper in project jsonschema2pojo by joelittlejohn.

the class ObjectRule method getConstructorProperties.

/**
     * Retrieve the list of properties to go in the constructor from node. This
     * is all properties listed in node["properties"] if ! onlyRequired, and
     * only required properties if onlyRequired.
     *
     * @param node
     * @return
     */
private LinkedHashSet<String> getConstructorProperties(JsonNode node, boolean onlyRequired) {
    if (!node.has("properties")) {
        return new LinkedHashSet<String>();
    }
    LinkedHashSet<String> rtn = new LinkedHashSet<String>();
    Set<String> draft4RequiredProperties = new HashSet<String>();
    // setup the set of required properties for draft4 style "required"
    if (onlyRequired && node.has("required")) {
        JsonNode requiredArray = node.get("required");
        if (requiredArray.isArray()) {
            for (JsonNode requiredEntry : requiredArray) {
                if (requiredEntry.isTextual()) {
                    draft4RequiredProperties.add(requiredEntry.asText());
                }
            }
        }
    }
    NameHelper nameHelper = ruleFactory.getNameHelper();
    for (Iterator<Map.Entry<String, JsonNode>> properties = node.get("properties").fields(); properties.hasNext(); ) {
        Map.Entry<String, JsonNode> property = properties.next();
        JsonNode propertyObj = property.getValue();
        if (onlyRequired) {
            // draft3 style
            if (propertyObj.has("required") && propertyObj.get("required").asBoolean()) {
                rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
            }
            // draft4 style
            if (draft4RequiredProperties.contains(property.getKey())) {
                rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
            }
        } else {
            rtn.add(nameHelper.getPropertyName(property.getKey(), property.getValue()));
        }
    }
    return rtn;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JsonNode(com.fasterxml.jackson.databind.JsonNode) NameHelper(org.jsonschema2pojo.util.NameHelper) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with NameHelper

use of org.jsonschema2pojo.util.NameHelper in project jsonschema2pojo by joelittlejohn.

the class RuleFactory method setGenerationConfig.

/**
     * The generation config options for type generation. These config options
     * will influence the java code generated by rules created by this factory.
     *
     * @param generationConfig
     *            Generation config
     */
public void setGenerationConfig(final GenerationConfig generationConfig) {
    this.generationConfig = generationConfig;
    this.nameHelper = new NameHelper(generationConfig);
}
Also used : NameHelper(org.jsonschema2pojo.util.NameHelper)

Aggregations

NameHelper (org.jsonschema2pojo.util.NameHelper)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1