diff --git a/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java b/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java
index bff4c594d..5c14c55ff 100644
--- a/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java
+++ b/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java
@@ -120,6 +120,8 @@ public class Jsonschema2PojoTask extends Task implements GenerationConfig {
private boolean includeAdditionalProperties = true;
private boolean includeAccessors = true;
+
+ private String target = "1.6";
/**
* Execute this task (it's expected that all relevant setters will have been
@@ -727,4 +729,9 @@ public boolean isIncludeAdditionalProperties() {
public boolean isIncludeAccessors() {
return includeAccessors;
}
+
+ @Override
+ public String getTarget() {
+ return target;
+ }
}
diff --git a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java
index bb0f75f52..0512e61c1 100644
--- a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java
+++ b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java
@@ -131,6 +131,9 @@ 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 = "Target version for generated source files.")
+ private String target = "1.6";
private static final int EXIT_OKAY = 0;
private static final int EXIT_ERROR = 1;
@@ -320,5 +323,10 @@ public boolean isIncludeAdditionalProperties() {
public boolean isIncludeAccessors() {
return !disableAccessors;
}
+
+ @Override
+ public String getTarget() {
+ return target;
+ }
}
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java
index ebbf19566..43a5cb5c1 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java
@@ -255,4 +255,11 @@ public boolean isIncludeAdditionalProperties() {
public boolean isIncludeAccessors() {
return true;
}
+
+ /**
+ * @return 1.6
+ */ @Override
+ public String getTarget() {
+ return "1.6";
+ }
}
\ No newline at end of file
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java
index 73c597161..858e2bc0c 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java
@@ -302,5 +302,12 @@ public interface GenerationConfig {
* methods and create public fields instead.
*/
boolean isIncludeAccessors();
+
+ /**
+ * Gets the 'target' configuration option
+ *
+ * @return The compilation target for the generated source.
+ */
+ String getTarget();
}
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/LanguageFeatures.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/LanguageFeatures.java
new file mode 100644
index 000000000..fe3641850
--- /dev/null
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/LanguageFeatures.java
@@ -0,0 +1,40 @@
+/**
+ * Copyright © 2010-2014 Nokia
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jsonschema2pojo.util;
+
+import org.jsonschema2pojo.GenerationConfig;
+import static java.util.Arrays.asList;
+
+import java.util.Collection;
+
+public class LanguageFeatures {
+
+ public static final Collection LESS_THAN_8
+ = asList("1.1", "1.2", "1.3", "1.4", "1.5", "5", "1.6", "6", "1.7", "7");
+ public static final Collection LESS_THAN_7
+ = asList("1.1", "1.2", "1.3", "1.4", "1.5", "5", "1.6", "6");
+ public static final Collection LESS_THAN_6
+ = asList("1.1", "1.2", "1.3", "1.4", "1.5", "5");
+
+ public static boolean canUseJava7( GenerationConfig config ) {
+ return !LESS_THAN_7.contains(config.getTarget());
+ }
+
+ public static boolean canUseJava8( GenerationConfig config ) {
+ return !LESS_THAN_8.contains(config.getTarget());
+ }
+}
diff --git a/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/util/LanguageFeaturesTest.java b/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/util/LanguageFeaturesTest.java
new file mode 100644
index 000000000..ad5c54baa
--- /dev/null
+++ b/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/util/LanguageFeaturesTest.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright © 2010-2014 Nokia
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jsonschema2pojo.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.jsonschema2pojo.GenerationConfig;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import static org.jsonschema2pojo.util.LanguageFeaturesTest.VersionEnum.*;
+import static org.mockito.Mockito.*;
+import static org.hamcrest.Matchers.*;
+import static org.hamcrest.MatcherAssert.*;
+
+@RunWith(Parameterized.class)
+public class LanguageFeaturesTest {
+
+ public static enum VersionEnum {
+
+ BEFORE_6(false, false, false),
+ MAX_6(true, false, false),
+ MAX_7(true, true, false),
+ MAX_8(true, true, true),
+ AFTER_8(true, true, true);
+
+ public final boolean canUse6;
+ public final boolean canUse7;
+ public final boolean canUse8;
+
+ VersionEnum(boolean canUse6, boolean canUse7, boolean canUse8) {
+ this.canUse6 = canUse6;
+ this.canUse7 = canUse7;
+ this.canUse8 = canUse8;
+ }
+ }
+
+ @Parameters
+ public static Collection