Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
flibbertigibbet committed Dec 9, 2015
2 parents 9ecb28b + 8e4bf17 commit 1adb7f4
Show file tree
Hide file tree
Showing 38 changed files with 1,418 additions and 72 deletions.
2 changes: 1 addition & 1 deletion jsonschema2pojo-ant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsonschema2pojo</artifactId>
<groupId>org.jsonschema2pojo</groupId>
<version>0.4.17-SNAPSHOT</version>
<version>0.4.18-SNAPSHOT</version>
</parent>

<artifactId>jsonschema2pojo-ant</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public class Jsonschema2PojoTask extends Task implements GenerationConfig {
private boolean includeAdditionalProperties = true;

private boolean includeAccessors = true;

private String targetVersion = "1.6";

private boolean includeDynamicAccessors = true;

/**
* Execute this task (it's expected that all relevant setters will have been
Expand Down Expand Up @@ -546,6 +550,28 @@ public void setIncludeAccessors(boolean includeAccessors) {
this.includeAccessors = includeAccessors;
}

/**
* Sets the 'targetVersion' property of this class
*
* @param targetVersion
* The target version for generated source files.
* <p>
* Default: <code>1.6</code>.
*/
public void setTargetVersion(String targetVersion) {
this.targetVersion = targetVersion;
}

/**
* Sets the 'includeDynamicAccessors' property of this class
*
* @param includeDynamicAccessors
* Whether to include dynamic getters, setters, and builders or to omit these methods.
*/
public void setIncludeDynamicAccessors(boolean includeDynamicAccessors) {
this.includeDynamicAccessors = includeDynamicAccessors;
}

@Override
public boolean isGenerateBuilders() {
return generateBuilders;
Expand Down Expand Up @@ -727,4 +753,14 @@ public boolean isIncludeAdditionalProperties() {
public boolean isIncludeAccessors() {
return includeAccessors;
}

@Override
public String getTargetVersion() {
return targetVersion;
}

@Override
public boolean isIncludeDynamicAccessors() {
return includeDynamicAccessors;
}
}
10 changes: 10 additions & 0 deletions jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ <h3>Parameters</h3>
<td valign="top">Whether to allow 'additional properties' support in objects. Setting this to false will disable additional properties support, regardless of the input schema(s).</td>
<td align="center" valign="top">No (default <code>true</code>)</td>
</tr>
<tr>
<td valign="top">includeDynamicAccessors</td>
<td valign="top">Whether to include dynamic getters, setters, and builders or to omit these methods.</td>
<td align="center" valign="top">No (default <code>true</code>)</td>
</tr>
<tr>
<td valign="top">includeConstructors</td>
<td valign="top">Whether to generate constructors for generated Java types</td>
Expand Down Expand Up @@ -228,6 +233,11 @@ <h3>Parameters</h3>
<td valign="top">Whether to use primitives (<code>long</code>, <code>double</code>, <code>boolean</code>) instead of wrapper types where possible when generating bean properties (has the side-effect of making those.</td>
<td align="center" valign="top">No (default <code>false</code>)</td>
</tr>
<tr>
<td valign="top">targetVersion</td>
<td valign="top">The target version for generated source files.</td>
<td align="center" valign="top">No (default <code>1.6</code>)</td>
</tr>
</table>

<h3>Examples</h3>
Expand Down
2 changes: 1 addition & 1 deletion jsonschema2pojo-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsonschema2pojo</artifactId>
<groupId>org.jsonschema2pojo</groupId>
<version>0.4.17-SNAPSHOT</version>
<version>0.4.18-SNAPSHOT</version>
</parent>

<artifactId>jsonschema2pojo-cli</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ public class Arguments implements GenerationConfig {

@Parameter(names = { "-da", "--disable-accessors" }, description = "Whether to omit getter/setter methods and create public fields instead.")
private boolean disableAccessors = false;

@Parameter(names = { "-tv", "--target-version" }, description = "The target version for generated source files.")
private String targetVersion = "1.6";

@Parameter(names = { "-dda", "--disable-dynamic-accessors" }, description = "Disable dynamic getter, setter, and builder support on generated types.")
private boolean disableDynamicAccessors = false;

private static final int EXIT_OKAY = 0;
private static final int EXIT_ERROR = 1;
Expand Down Expand Up @@ -321,4 +327,14 @@ public boolean isIncludeAccessors() {
return !disableAccessors;
}

@Override
public String getTargetVersion() {
return targetVersion;
}

@Override
public boolean isIncludeDynamicAccessors() {
return !disableDynamicAccessors;
}

}
2 changes: 1 addition & 1 deletion jsonschema2pojo-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsonschema2pojo</artifactId>
<groupId>org.jsonschema2pojo</groupId>
<version>0.4.17-SNAPSHOT</version>
<version>0.4.18-SNAPSHOT</version>
</parent>

<artifactId>jsonschema2pojo-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,20 @@ public boolean isIncludeAdditionalProperties() {
public boolean isIncludeAccessors() {
return true;
}
}

/**
* @return <code>1.6</code>
*/
@Override
public String getTargetVersion() {
return "1.6";
}

/**
* @return <code>true</code>
*/
@Override
public boolean isIncludeDynamicAccessors() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,20 @@ public interface GenerationConfig {
* methods and create public fields instead.
*/
boolean isIncludeAccessors();

/**
* Gets the 'targetVersion' configuration option
*
* @return The target version for generated source files.
*/
String getTargetVersion();

/**
* Gets the `includeDynamicAccessors` configuraiton option
*
* @return Whether to include dynamic getters, setters, and builders
* or to omit these methods.
*/
boolean isIncludeDynamicAccessors();

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Schema create(Schema parent, String path) {
URI id = (parent == null || parent.getId() == null) ? URI.create(path) : parent.getId().resolve(path);

if (selfReferenceWithoutParentFile(parent, path)) {
schemas.put(id, new Schema(id, fragmentResolver.resolve(parent.getParentContent(), path), parent.getContent()));
schemas.put(id, new Schema(id, fragmentResolver.resolve(parent.getParentContent(), path), parent.getParentContent()));
return schemas.get(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ public JDefinedClass apply(String nodeName, JsonNode node, JDefinedClass jclass,

JFieldVar field = addAdditionalPropertiesField(jclass, propertyType);

if (ruleFactory.getGenerationConfig().isIncludeAccessors()) {
addGetter(jclass, field);
addSetter(jclass, propertyType, field);
}
addGetter(jclass, field);

addSetter(jclass, propertyType, field);

if (ruleFactory.getGenerationConfig().isGenerateBuilders()) {
addBuilder(jclass, propertyType, field);
Expand All @@ -126,7 +125,7 @@ private JFieldVar addAdditionalPropertiesField(JDefinedClass jclass, JType prope
JClass propertiesMapImplType = jclass.owner().ref(HashMap.class);
propertiesMapImplType = propertiesMapImplType.narrow(jclass.owner().ref(String.class), propertyType.boxify());

JFieldVar field = jclass.field(fieldScopeModifier(), propertiesMapType, "additionalProperties");
JFieldVar field = jclass.field(JMod.PRIVATE, propertiesMapType, "additionalProperties");

ruleFactory.getAnnotator().additionalPropertiesField(field, jclass, "additionalProperties");

Expand All @@ -135,10 +134,6 @@ private JFieldVar addAdditionalPropertiesField(JDefinedClass jclass, JType prope
return field;
}

private int fieldScopeModifier() {
return ruleFactory.getGenerationConfig().isIncludeAccessors() ? JMod.PRIVATE : JMod.PUBLIC;
}

private void addSetter(JDefinedClass jclass, JType propertyType, JFieldVar field) {
JMethod setter = jclass.method(JMod.PUBLIC, void.class, "setAdditionalProperty");

Expand Down
Loading

0 comments on commit 1adb7f4

Please sign in to comment.