Skip to content

Commit daa1fb4

Browse files
authored
Merge pull request #81 from jsonschema2dataclass/AndroidDevelopment
2 parents 8a7c2d5 + f5d9adb commit daa1fb4

19 files changed

+853
-19
lines changed

.github/workflows/Android-CI.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: Android Sample
33
on: [pull_request]
44

55
jobs:
6-
buildTest:
7-
name: Build JDK ${{ matrix.java_version }}
6+
buildDemo:
7+
name: Build Demo JDK ${{ matrix.java_version }}
88
runs-on: ubuntu-latest
99
defaults:
1010
run:
@@ -25,3 +25,26 @@ jobs:
2525
uses: malinskiy/action-android/install-sdk@release/0.1.1
2626
- name: Build project
2727
run: ./gradlew assembleDebug
28+
29+
buildDevelopment:
30+
name: Build Dev JDK ${{ matrix.java_version }}
31+
runs-on: ubuntu-latest
32+
defaults:
33+
run:
34+
working-directory: demo/androidDev
35+
strategy:
36+
matrix:
37+
java_version: [1.8, 11, 15]
38+
steps:
39+
- name: Checkout
40+
uses: actions/[email protected]
41+
with:
42+
fetch-depth: 0
43+
- name: Install JDK ${{ matrix.java_version }}
44+
uses: actions/setup-java@v1
45+
with:
46+
java-version: ${{ matrix.java_version }}
47+
- name: Install Android SDK
48+
uses: malinskiy/action-android/install-sdk@release/0.1.1
49+
- name: Build project
50+
run: ./gradlew assembleDebug

.github/workflows/gradle-wrapper-validation.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ jobs:
3333
steps:
3434
- uses: actions/checkout@v2
3535
- uses: gradle/wrapper-validation-action@v1
36+
validationAndroidDev:
37+
name: "Validation Android development"
38+
runs-on: ubuntu-latest
39+
defaults:
40+
run:
41+
working-directory: demo/androidDev
42+
steps:
43+
- uses: actions/checkout@v2
44+
- uses: gradle/wrapper-validation-action@v1

demo/android/app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jsonSchema2Pojo {
5656

5757
// Location of the JSON Schema file(s). This may refer to a single file or a directory of files.
5858
//source = files("${sourceSets.main.output.resourcesDir}/json")
59-
source = files("${project.rootDir}/schema")
59+
source.setFrom files("${project.rootDir}/schema")
6060

6161
// Target directory for generated Java source files. The plugin will ignore this value for Android projects and will generate the classes into a generated source folder for each build variant and add this directory to the
6262
// java source set so the compiler will find and compile the newly generated source files.
@@ -119,14 +119,14 @@ jsonSchema2Pojo {
119119
// that have been generated previously. <strong>Be warned</strong>, when activated this option
120120
// will cause jsonschema2pojo to <strong>indiscriminately delete the entire contents of the target
121121
// directory (all files and folders)</strong> before it begins generating sources.
122-
boolean removeOldOutput = true
122+
removeOldOutput = true
123123

124124
// The character encoding that should be used when writing the generated Java source files
125-
String outputEncoding = 'UTF-8'
125+
outputEncoding = 'UTF-8'
126126

127127
// Whether to use {@link org.joda.time.DateTime} instead of {@link java.util.Date} when adding
128128
// date type fields to generated Java types.
129-
boolean useJodaDates = false
129+
useJodaDates = false
130130

131131
// Whether to initialize Set and List fields as empty collections, or leave them as null.
132132
boolean initializeCollections = true

demo/android/lib/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jsonSchema2Pojo {
4949

5050
// Location of the JSON Schema file(s). This may refer to a single file or a directory of files.
5151
//source = files("${sourceSets.main.output.resourcesDir}/json")
52-
source = files("${project.rootDir}/schema")
52+
source.setFrom files("${project.rootDir}/schema")
5353

5454
// Target directory for generated Java source files. The plugin will ignore this value for Android projects and will generate the classes into a generated source folder for each build variant and add this directory to the
5555
// java source set so the compiler will find and compile the newly generated source files.
@@ -113,15 +113,15 @@ jsonSchema2Pojo {
113113
// that have been generated previously. <strong>Be warned</strong>, when activated this option
114114
// will cause jsonschema2pojo to <strong>indiscriminately delete the entire contents of the target
115115
// directory (all files and folders)</strong> before it begins generating sources.
116-
boolean removeOldOutput = true
116+
removeOldOutput = true
117117

118118
// The character encoding that should be used when writing the generated Java source files
119-
String outputEncoding = 'UTF-8'
119+
outputEncoding = 'UTF-8'
120120

121121
// Whether to use {@link org.joda.time.DateTime} instead of {@link java.util.Date} when adding
122122
// date type fields to generated Java types.
123-
boolean useJodaDates = false
123+
useJodaDates = false
124124

125125
// Whether to initialize Set and List fields as empty collections, or leave them as null.
126-
boolean initializeCollections = true
126+
initializeCollections = true
127127
}

demo/android/lib2/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ jsonSchema2Pojo {
109109
// that have been generated previously. <strong>Be warned</strong>, when activated this option
110110
// will cause jsonschema2pojo to <strong>indiscriminately delete the entire contents of the target
111111
// directory (all files and folders)</strong> before it begins generating sources.
112-
boolean removeOldOutput = true
112+
removeOldOutput = true
113113

114114
// The character encoding that should be used when writing the generated Java source files
115-
String outputEncoding = 'UTF-8'
115+
outputEncoding = 'UTF-8'
116116

117117
// Whether to use {@link org.joda.time.DateTime} instead of {@link java.util.Date} when adding
118118
// date type fields to generated Java types.
119-
boolean useJodaDates = false
119+
useJodaDates = false
120120

121121
// Whether to initialize Set and List fields as empty collections, or leave them as null.
122-
boolean initializeCollections = true
122+
initializeCollections = true
123123
}

demo/androidDev/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.gradle
2+
local.properties
3+
.idea
4+
.DS_Store
5+
build

demo/androidDev/app/build.gradle

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
plugins {
2+
id 'com.android.application'
3+
id "org.jsonschema2dataclass"
4+
}
5+
6+
android {
7+
compileSdkVersion 30
8+
9+
defaultConfig {
10+
applicationId "org.jsonschema2dataclass.android"
11+
minSdkVersion 17
12+
targetSdkVersion 30
13+
versionCode 1
14+
versionName "1.0"
15+
}
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
}
20+
}
21+
22+
packagingOptions {
23+
exclude 'META-INF/LICENSE.txt'
24+
}
25+
26+
compileOptions {
27+
sourceCompatibility 1.8
28+
targetCompatibility 1.8
29+
}
30+
31+
sourceSets {
32+
main {
33+
manifest.srcFile '../../android/app/src/main/AndroidManifest.xml'
34+
java.srcDirs = ['../../android/app/src/main/java']
35+
resources.srcDirs = ['../../android/app/src/main/resources']
36+
res.srcDirs = ['../../android/app/src/main/res']
37+
}
38+
}
39+
}
40+
41+
dependencies {
42+
implementation 'androidx.appcompat:appcompat:1.2.0'
43+
44+
// Required for @Generated annotation
45+
implementation 'org.glassfish:javax.annotation:10.0-b28'
46+
implementation 'com.google.code.gson:gson:2.8.6'
47+
implementation 'com.squareup.moshi:moshi:1.11.0'
48+
// Required if generating JSR-303 annotations
49+
implementation 'javax.validation:validation-api:2.0.1.Final'
50+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.2'
51+
52+
}
53+
54+
// Each configuration is set to the default value
55+
jsonSchema2Pojo {
56+
// Whether to generate builder-style methods of the form withXxx(value) (that return this),
57+
// alongside the standard, void-return setters.
58+
generateBuilders = false
59+
60+
// Whether to use primitives (long, double, boolean) instead of wrapper types where possible
61+
// when generating bean properties (has the side-effect of making those properties non-null).
62+
usePrimitives = false
63+
64+
// Location of the JSON Schema file(s). This may refer to a single file or a directory of files.
65+
//source = files("${sourceSets.main.output.resourcesDir}/json")
66+
source.setFrom files("${project.rootDir}/schema")
67+
68+
// Target directory for generated Java source files. The plugin will ignore this value for Android projects and will generate the classes into a generated source folder for each build variant and add this directory to the
69+
// java source set so the compiler will find and compile the newly generated source files.
70+
// targetDirectory = file("${project.rootDir}/build/generated-sources/js2p")
71+
72+
// Package name used for generated Java classes (for types where a fully qualified name has not
73+
// been supplied in the schema using the 'javaType' property).
74+
targetPackage = 'com.oosocial.clarityn.rest.clarityn.model'
75+
76+
// The characters that should be considered as word delimiters when creating Java Bean property
77+
// names from JSON property names. If blank or not set, JSON properties will be considered to
78+
// contain a single word when creating Java Bean property names.
79+
propertyWordDelimiters = ''
80+
81+
// Whether to use the java type long (or Long) instead of int (or Integer) when representing the
82+
// JSON Schema type 'integer'.
83+
useLongIntegers = false
84+
85+
// Whether to use the java type double (or Double) instead of float (or Float) when representing
86+
// the JSON Schema type 'number'.
87+
useDoubleNumbers = true
88+
89+
// Whether to include hashCode and equals methods in generated Java types.
90+
includeHashcodeAndEquals = true
91+
92+
// Whether to include a toString method in generated Java types.
93+
includeToString = true
94+
95+
// The style of annotations to use in the generated Java types. Supported values:
96+
// - jackson (alias of jackson2)
97+
// - jackson2 (apply annotations from the Jackson 2.x library)
98+
// - gson (apply annotations from the Gson library)
99+
// - moshi1 (apply annotations from the Moshi 1.x library)
100+
// - none (apply no annotations at all)
101+
annotationStyle = 'gson'
102+
103+
// A fully qualified class name, referring to a custom annotator class that implements
104+
// by annotationStyle. If you want to use the custom annotator alone, set annotationStyle to none.
105+
customAnnotator = 'org.jsonschema2pojo.NoopAnnotator'
106+
107+
// Whether to include JSR-303/349 annotations (for schema rules like minimum, maximum, etc) in
108+
// generated Java types. Schema rules and the annotation they produce:
109+
// - maximum = @DecimalMax
110+
// - minimum = @DecimalMin
111+
// - minItems,maxItems = @Size
112+
// - minLength,maxLength = @Size
113+
// - pattern = @Pattern
114+
// - required = @NotNull
115+
// Any Java fields which are an object or array of objects will be annotated with @Valid to
116+
// support validation of an entire document tree.
117+
includeJsr303Annotations = true
118+
119+
// The type of input documents that will be read. Supported values:
120+
// - jsonschema (schema documents, containing formal rules that describe the structure of json data)
121+
// - json (documents that represent an example of the kind of json data that the generated Java types
122+
// will be mapped to)
123+
sourceType = 'jsonschema'
124+
125+
// Whether to empty the target directory before generation occurs, to clear out all source files
126+
// that have been generated previously. <strong>Be warned</strong>, when activated this option
127+
// will cause jsonschema2pojo to <strong>indiscriminately delete the entire contents of the target
128+
// directory (all files and folders)</strong> before it begins generating sources.
129+
removeOldOutput = true
130+
131+
// The character encoding that should be used when writing the generated Java source files
132+
outputEncoding = 'UTF-8'
133+
134+
// Whether to use {@link org.joda.time.DateTime} instead of {@link java.util.Date} when adding
135+
// date type fields to generated Java types.
136+
useJodaDates = false
137+
138+
// Whether to initialize Set and List fields as empty collections, or leave them as null.
139+
initializeCollections = true
140+
// Include @Generated annotation
141+
includeGeneratedAnnotation = true
142+
}

demo/androidDev/build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
jcenter()
5+
maven { url uri('../..') }
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:4.1.3'
9+
}
10+
}
11+
plugins {
12+
id 'org.jsonschema2dataclass' version '+' apply false
13+
}
14+
15+
allprojects {
16+
repositories {
17+
google()
18+
jcenter()
19+
}
20+
}

demo/androidDev/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
android.enableJetifier=true
2+
android.useAndroidX=true
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)