diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/DynamicPropertiesRule.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/DynamicPropertiesRule.java index 8ca01be3c..31ea86c66 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/DynamicPropertiesRule.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/DynamicPropertiesRule.java @@ -50,6 +50,12 @@ import com.sun.codemodel.JTypeVar; import com.sun.codemodel.JVar; +/** + * Adds methods for dynamically getting, setting, and building properties by name. + * + * @author Christian Trimble + * + */ public class DynamicPropertiesRule implements Rule { public static final String NOT_FOUND_VALUE_FIELD = "NOT_FOUND_VALUE"; @@ -65,6 +71,33 @@ public DynamicPropertiesRule(RuleFactory ruleFactory) { this.ruleFactory = ruleFactory; } + /** + * This rule adds dynamic getter, setter and builder methods based on the properties and additional properties + * defined in a schema. + *

+ * If accessors are being generated, then methods for getting and setting properties by name will be added. These + * methods first attempt to call the appropriate getter or setter for the property. It no property with the supplied + * name is defined, then the additional properties map is used. + *

+ * If builders are being generated, then a method for building properties by name will be added. This method first + * attempts to call the builder for the property. If no property with the supplied name is defined, then the additional + * properties map is used. + *

+ * The methods generated by this class throw an IllegalArgumentException, if the name specified for the property is unknown and + * additional properties are not enabled. A ClassCastException will be thrown, when the value being set is incompatible with the + * type of the named property. + * + * @param nodeName + * the name of the node for which dynamic getters, setters, and builders are being added. + * @param node + * the properties node, containing property names and their + * definition + * @param jclass + * the Java type which will have the given properties added + * @param currentSchema + * the schema being implemented + * @return the given jclass + */ @Override public JDefinedClass apply(String nodeName, JsonNode node, JDefinedClass jclass, Schema currentSchema) { if (!ruleFactory.getGenerationConfig().isIncludeDynamicAccessors()) { @@ -260,16 +293,6 @@ private JMethod addPublicWithMethod(JDefinedClass jclass, JsonNode propertiesNod return method; } - /** - * protected boolean set$( String name, Object value ) { switch( name ) { // - * cases for the properties defined on this schema. default: return - * super.set$( name, value ); // if extends return false; // if not extends. - * } } - * - * @param jclass - * @param currentSchema - * @param node - */ private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode, Schema currentSchema) { JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME); JVar nameParam = method.param(String.class, "name");