quicktype 18.0.6 → 19.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
- package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
- package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
- package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
- package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
- package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
- package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
- package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
- package/dist/{cli/index.d.ts → index.d.ts} +2 -1
- package/dist/{cli/index.js → index.js} +4 -4
- package/package.json +61 -77
- package/dist/quicktype-core/Annotation.d.ts +0 -8
- package/dist/quicktype-core/Annotation.js +0 -16
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
- package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
- package/dist/quicktype-core/DateTime.d.ts +0 -10
- package/dist/quicktype-core/DateTime.js +0 -57
- package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
- package/dist/quicktype-core/DeclarationIR.js +0 -167
- package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
- package/dist/quicktype-core/GatherNames.d.ts +0 -2
- package/dist/quicktype-core/GatherNames.js +0 -333
- package/dist/quicktype-core/Graph.d.ts +0 -12
- package/dist/quicktype-core/Graph.js +0 -220
- package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
- package/dist/quicktype-core/GraphRewriting.js +0 -421
- package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
- package/dist/quicktype-core/MakeTransformations.js +0 -193
- package/dist/quicktype-core/MarkovChain.d.ts +0 -15
- package/dist/quicktype-core/MarkovChain.js +0 -154
- package/dist/quicktype-core/Messages.d.ts +0 -294
- package/dist/quicktype-core/Messages.js +0 -105
- package/dist/quicktype-core/Naming.d.ts +0 -64
- package/dist/quicktype-core/Naming.js +0 -356
- package/dist/quicktype-core/Renderer.d.ts +0 -50
- package/dist/quicktype-core/Renderer.js +0 -274
- package/dist/quicktype-core/RendererOptions.d.ts +0 -71
- package/dist/quicktype-core/RendererOptions.js +0 -141
- package/dist/quicktype-core/Run.d.ts +0 -174
- package/dist/quicktype-core/Run.js +0 -393
- package/dist/quicktype-core/Source.d.ts +0 -65
- package/dist/quicktype-core/Source.js +0 -204
- package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
- package/dist/quicktype-core/TargetLanguage.js +0 -66
- package/dist/quicktype-core/Transformers.d.ts +0 -209
- package/dist/quicktype-core/Transformers.js +0 -836
- package/dist/quicktype-core/Type.d.ts +0 -206
- package/dist/quicktype-core/Type.js +0 -716
- package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
- package/dist/quicktype-core/TypeBuilder.js +0 -324
- package/dist/quicktype-core/TypeGraph.d.ts +0 -75
- package/dist/quicktype-core/TypeGraph.js +0 -420
- package/dist/quicktype-core/TypeUtils.d.ts +0 -33
- package/dist/quicktype-core/TypeUtils.js +0 -230
- package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
- package/dist/quicktype-core/UnifyClasses.js +0 -159
- package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
- package/dist/quicktype-core/UnionBuilder.js +0 -282
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
- package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
- package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
- package/dist/quicktype-core/attributes/Constraints.js +0 -172
- package/dist/quicktype-core/attributes/Description.d.ts +0 -9
- package/dist/quicktype-core/attributes/Description.js +0 -97
- package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
- package/dist/quicktype-core/attributes/EnumValues.js +0 -31
- package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
- package/dist/quicktype-core/attributes/StringTypes.js +0 -189
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
- package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
- package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
- package/dist/quicktype-core/attributes/TypeNames.js +0 -274
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
- package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
- package/dist/quicktype-core/index.d.ts +0 -48
- package/dist/quicktype-core/index.js +0 -180
- package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
- package/dist/quicktype-core/input/CompressedJSON.js +0 -276
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
- package/dist/quicktype-core/input/Inference.d.ts +0 -22
- package/dist/quicktype-core/input/Inference.js +0 -240
- package/dist/quicktype-core/input/Inputs.d.ts +0 -48
- package/dist/quicktype-core/input/Inputs.js +0 -145
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
- package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
- package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
- package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
- package/dist/quicktype-core/input/PostmanCollection.js +0 -60
- package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
- package/dist/quicktype-core/input/io/NodeIO.js +0 -87
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
- package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
- package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
- package/dist/quicktype-core/language/All.d.ts +0 -3
- package/dist/quicktype-core/language/All.js +0 -57
- package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
- package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
- package/dist/quicktype-core/language/CSharp.d.ts +0 -201
- package/dist/quicktype-core/language/CSharp.js +0 -1850
- package/dist/quicktype-core/language/Crystal.d.ts +0 -37
- package/dist/quicktype-core/language/Crystal.js +0 -337
- package/dist/quicktype-core/language/Dart.d.ts +0 -66
- package/dist/quicktype-core/language/Dart.js +0 -576
- package/dist/quicktype-core/language/Elm.d.ts +0 -58
- package/dist/quicktype-core/language/Elm.js +0 -522
- package/dist/quicktype-core/language/Golang.d.ts +0 -51
- package/dist/quicktype-core/language/Golang.js +0 -460
- package/dist/quicktype-core/language/Haskell.d.ts +0 -56
- package/dist/quicktype-core/language/Haskell.js +0 -411
- package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
- package/dist/quicktype-core/language/JSONSchema.js +0 -169
- package/dist/quicktype-core/language/Java.d.ts +0 -125
- package/dist/quicktype-core/language/Java.js +0 -1081
- package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
- package/dist/quicktype-core/language/JavaScript.js +0 -435
- package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
- package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
- package/dist/quicktype-core/language/Kotlin.js +0 -832
- package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
- package/dist/quicktype-core/language/Objective-C.js +0 -777
- package/dist/quicktype-core/language/Php.d.ts +0 -80
- package/dist/quicktype-core/language/Php.js +0 -702
- package/dist/quicktype-core/language/Pike.d.ts +0 -37
- package/dist/quicktype-core/language/Pike.js +0 -276
- package/dist/quicktype-core/language/Python.d.ts +0 -107
- package/dist/quicktype-core/language/Python.js +0 -969
- package/dist/quicktype-core/language/Rust.d.ts +0 -56
- package/dist/quicktype-core/language/Rust.js +0 -309
- package/dist/quicktype-core/language/Swift.d.ts +0 -96
- package/dist/quicktype-core/language/Swift.js +0 -1211
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
- package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
- package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
- package/dist/quicktype-core/language/ruby/index.js +0 -557
- package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
- package/dist/quicktype-core/language/ruby/keywords.js +0 -358
- package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
- package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
- package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
- package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
- package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
- package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
- package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
- package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
- package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
- package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
- package/dist/quicktype-core/support/Acronyms.js +0 -1128
- package/dist/quicktype-core/support/Chance.d.ts +0 -38
- package/dist/quicktype-core/support/Chance.js +0 -2146
- package/dist/quicktype-core/support/Converters.d.ts +0 -6
- package/dist/quicktype-core/support/Converters.js +0 -16
- package/dist/quicktype-core/support/Strings.d.ts +0 -44
- package/dist/quicktype-core/support/Strings.js +0 -525
- package/dist/quicktype-core/support/Support.d.ts +0 -29
- package/dist/quicktype-core/support/Support.js +0 -162
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
- package/dist/quicktype-graphql-input/index.d.ts +0 -17
- package/dist/quicktype-graphql-input/index.js +0 -407
- package/dist/quicktype-typescript-input/index.d.ts +0 -2
- package/dist/quicktype-typescript-input/index.js +0 -98
|
@@ -1,1081 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JacksonRenderer = exports.JavaRenderer = exports.javaNameStyle = exports.stringEscape = exports.JavaTargetLanguage = exports.javaOptions = void 0;
|
|
4
|
-
const Annotation_1 = require("../Annotation");
|
|
5
|
-
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
6
|
-
const Naming_1 = require("../Naming");
|
|
7
|
-
const RendererOptions_1 = require("../RendererOptions");
|
|
8
|
-
const Source_1 = require("../Source");
|
|
9
|
-
const Acronyms_1 = require("../support/Acronyms");
|
|
10
|
-
const Strings_1 = require("../support/Strings");
|
|
11
|
-
const Support_1 = require("../support/Support");
|
|
12
|
-
const TargetLanguage_1 = require("../TargetLanguage");
|
|
13
|
-
const Type_1 = require("../Type");
|
|
14
|
-
const TypeUtils_1 = require("../TypeUtils");
|
|
15
|
-
exports.javaOptions = {
|
|
16
|
-
useList: new RendererOptions_1.EnumOption("array-type", "Use T[] or List<T>", [
|
|
17
|
-
["array", false],
|
|
18
|
-
["list", true]
|
|
19
|
-
], "array"),
|
|
20
|
-
justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
|
|
21
|
-
dateTimeProvider: new RendererOptions_1.EnumOption("datetime-provider", "Date time provider type", [
|
|
22
|
-
["java8", "java8"],
|
|
23
|
-
["legacy", "legacy"]
|
|
24
|
-
], "java8"),
|
|
25
|
-
acronymStyle: (0, Acronyms_1.acronymOption)(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
26
|
-
// FIXME: Do this via a configurable named eventually.
|
|
27
|
-
packageName: new RendererOptions_1.StringOption("package", "Generated package name", "NAME", "io.quicktype"),
|
|
28
|
-
lombok: new RendererOptions_1.BooleanOption("lombok", "Use lombok", false, "primary"),
|
|
29
|
-
lombokCopyAnnotations: new RendererOptions_1.BooleanOption("lombok-copy-annotations", "Copy accessor annotations", true, "secondary")
|
|
30
|
-
};
|
|
31
|
-
class JavaTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
32
|
-
constructor() {
|
|
33
|
-
super("Java", ["java"], "java");
|
|
34
|
-
}
|
|
35
|
-
getOptions() {
|
|
36
|
-
return [
|
|
37
|
-
exports.javaOptions.useList,
|
|
38
|
-
exports.javaOptions.justTypes,
|
|
39
|
-
exports.javaOptions.dateTimeProvider,
|
|
40
|
-
exports.javaOptions.acronymStyle,
|
|
41
|
-
exports.javaOptions.packageName,
|
|
42
|
-
exports.javaOptions.lombok,
|
|
43
|
-
exports.javaOptions.lombokCopyAnnotations
|
|
44
|
-
];
|
|
45
|
-
}
|
|
46
|
-
get supportsUnionsWithBothNumberTypes() {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
makeRenderer(renderContext, untypedOptionValues) {
|
|
50
|
-
const options = (0, RendererOptions_1.getOptionValues)(exports.javaOptions, untypedOptionValues);
|
|
51
|
-
if (options.justTypes) {
|
|
52
|
-
return new JavaRenderer(this, renderContext, options);
|
|
53
|
-
}
|
|
54
|
-
return new JacksonRenderer(this, renderContext, options);
|
|
55
|
-
}
|
|
56
|
-
get stringTypeMapping() {
|
|
57
|
-
const mapping = new Map();
|
|
58
|
-
mapping.set("date", "date");
|
|
59
|
-
mapping.set("time", "time");
|
|
60
|
-
mapping.set("date-time", "date-time");
|
|
61
|
-
mapping.set("uuid", "uuid");
|
|
62
|
-
return mapping;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.JavaTargetLanguage = JavaTargetLanguage;
|
|
66
|
-
const javaKeywords = [
|
|
67
|
-
"Object",
|
|
68
|
-
"Class",
|
|
69
|
-
"System",
|
|
70
|
-
"Long",
|
|
71
|
-
"Double",
|
|
72
|
-
"Boolean",
|
|
73
|
-
"String",
|
|
74
|
-
"List",
|
|
75
|
-
"Map",
|
|
76
|
-
"UUID",
|
|
77
|
-
"Exception",
|
|
78
|
-
"IOException",
|
|
79
|
-
"Override",
|
|
80
|
-
"abstract",
|
|
81
|
-
"continue",
|
|
82
|
-
"for",
|
|
83
|
-
"new",
|
|
84
|
-
"switch",
|
|
85
|
-
"assert",
|
|
86
|
-
"default",
|
|
87
|
-
"goto",
|
|
88
|
-
"package",
|
|
89
|
-
"synchronized",
|
|
90
|
-
"boolean",
|
|
91
|
-
"do",
|
|
92
|
-
"if",
|
|
93
|
-
"private",
|
|
94
|
-
"this",
|
|
95
|
-
"break",
|
|
96
|
-
"double",
|
|
97
|
-
"implements",
|
|
98
|
-
"protected",
|
|
99
|
-
"throw",
|
|
100
|
-
"byte",
|
|
101
|
-
"else",
|
|
102
|
-
"import",
|
|
103
|
-
"public",
|
|
104
|
-
"throws",
|
|
105
|
-
"case",
|
|
106
|
-
"enum",
|
|
107
|
-
"instanceof",
|
|
108
|
-
"return",
|
|
109
|
-
"transient",
|
|
110
|
-
"catch",
|
|
111
|
-
"extends",
|
|
112
|
-
"int",
|
|
113
|
-
"short",
|
|
114
|
-
"try",
|
|
115
|
-
"char",
|
|
116
|
-
"final",
|
|
117
|
-
"interface",
|
|
118
|
-
"static",
|
|
119
|
-
"void",
|
|
120
|
-
"class",
|
|
121
|
-
"finally",
|
|
122
|
-
"long",
|
|
123
|
-
"strictfp",
|
|
124
|
-
"volatile",
|
|
125
|
-
"const",
|
|
126
|
-
"float",
|
|
127
|
-
"native",
|
|
128
|
-
"super",
|
|
129
|
-
"while",
|
|
130
|
-
"null",
|
|
131
|
-
"false",
|
|
132
|
-
"true"
|
|
133
|
-
];
|
|
134
|
-
exports.stringEscape = (0, Strings_1.utf16ConcatMap)((0, Strings_1.escapeNonPrintableMapper)(Strings_1.isAscii, Strings_1.standardUnicodeHexEscape));
|
|
135
|
-
function isStartCharacter(codePoint) {
|
|
136
|
-
if (codePoint === 0x5f)
|
|
137
|
-
return true; // underscore
|
|
138
|
-
return (0, Strings_1.isAscii)(codePoint) && (0, Strings_1.isLetter)(codePoint);
|
|
139
|
-
}
|
|
140
|
-
function isPartCharacter(codePoint) {
|
|
141
|
-
return isStartCharacter(codePoint) || ((0, Strings_1.isAscii)(codePoint) && (0, Strings_1.isDigit)(codePoint));
|
|
142
|
-
}
|
|
143
|
-
const legalizeName = (0, Strings_1.utf16LegalizeCharacters)(isPartCharacter);
|
|
144
|
-
function javaNameStyle(startWithUpper, upperUnderscore, original, acronymsStyle = Strings_1.allUpperWordStyle) {
|
|
145
|
-
const words = (0, Strings_1.splitIntoWords)(original);
|
|
146
|
-
return (0, Strings_1.combineWords)(words, legalizeName, upperUnderscore ? Strings_1.allUpperWordStyle : startWithUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, upperUnderscore ? Strings_1.allUpperWordStyle : Strings_1.firstUpperWordStyle, upperUnderscore || startWithUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, acronymsStyle, upperUnderscore ? "_" : "", isStartCharacter);
|
|
147
|
-
}
|
|
148
|
-
exports.javaNameStyle = javaNameStyle;
|
|
149
|
-
class JavaDateTimeProvider {
|
|
150
|
-
_renderer;
|
|
151
|
-
_className;
|
|
152
|
-
constructor(_renderer, _className) {
|
|
153
|
-
this._renderer = _renderer;
|
|
154
|
-
this._className = _className;
|
|
155
|
-
}
|
|
156
|
-
shouldEmitDateTimeConverter = true;
|
|
157
|
-
shouldEmitTimeConverter = true;
|
|
158
|
-
shouldEmitDateConverter = true;
|
|
159
|
-
}
|
|
160
|
-
class Java8DateTimeProvider extends JavaDateTimeProvider {
|
|
161
|
-
keywords = [
|
|
162
|
-
"LocalDate",
|
|
163
|
-
"OffsetDateTime",
|
|
164
|
-
"OffsetTime",
|
|
165
|
-
"ZoneOffset",
|
|
166
|
-
"ZonedDateTime",
|
|
167
|
-
"DateTimeFormatter",
|
|
168
|
-
"DateTimeFormatterBuilder",
|
|
169
|
-
"ChronoField"
|
|
170
|
-
];
|
|
171
|
-
dateTimeImports = ["java.time.OffsetDateTime"];
|
|
172
|
-
dateImports = ["java.time.LocalDate"];
|
|
173
|
-
timeImports = ["java.time.OffsetTime"];
|
|
174
|
-
converterImports = [
|
|
175
|
-
"java.time.LocalDate",
|
|
176
|
-
"java.time.OffsetDateTime",
|
|
177
|
-
"java.time.OffsetTime",
|
|
178
|
-
"java.time.ZoneOffset",
|
|
179
|
-
"java.time.ZonedDateTime",
|
|
180
|
-
"java.time.format.DateTimeFormatter",
|
|
181
|
-
"java.time.format.DateTimeFormatterBuilder",
|
|
182
|
-
"java.time.temporal.ChronoField"
|
|
183
|
-
];
|
|
184
|
-
dateTimeType = "OffsetDateTime";
|
|
185
|
-
dateType = "LocalDate";
|
|
186
|
-
timeType = "OffsetTime";
|
|
187
|
-
dateTimeJacksonAnnotations = [];
|
|
188
|
-
dateJacksonAnnotations = [];
|
|
189
|
-
timeJacksonAnnotations = [];
|
|
190
|
-
emitDateTimeConverters() {
|
|
191
|
-
this._renderer.ensureBlankLine();
|
|
192
|
-
this._renderer.emitLine("private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()");
|
|
193
|
-
this._renderer.indent(() => this._renderer.indent(() => {
|
|
194
|
-
this._renderer.emitLine(".appendOptional(DateTimeFormatter.ISO_DATE_TIME)");
|
|
195
|
-
this._renderer.emitLine(".appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME)");
|
|
196
|
-
this._renderer.emitLine(".appendOptional(DateTimeFormatter.ISO_INSTANT)");
|
|
197
|
-
this._renderer.emitLine('.appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SX"))');
|
|
198
|
-
this._renderer.emitLine('.appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssX"))');
|
|
199
|
-
this._renderer.emitLine('.appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))');
|
|
200
|
-
this._renderer.emitLine(".toFormatter()");
|
|
201
|
-
this._renderer.emitLine(".withZone(ZoneOffset.UTC);");
|
|
202
|
-
}));
|
|
203
|
-
this._renderer.ensureBlankLine();
|
|
204
|
-
this._renderer.emitBlock("public static OffsetDateTime parseDateTimeString(String str)", () => {
|
|
205
|
-
this._renderer.emitLine("return ZonedDateTime.from(Converter.DATE_TIME_FORMATTER.parse(str)).toOffsetDateTime();");
|
|
206
|
-
});
|
|
207
|
-
this._renderer.ensureBlankLine();
|
|
208
|
-
this._renderer.emitLine("private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder()");
|
|
209
|
-
this._renderer.indent(() => this._renderer.indent(() => {
|
|
210
|
-
this._renderer.emitLine(".appendOptional(DateTimeFormatter.ISO_TIME)");
|
|
211
|
-
this._renderer.emitLine(".appendOptional(DateTimeFormatter.ISO_OFFSET_TIME)");
|
|
212
|
-
this._renderer.emitLine(".parseDefaulting(ChronoField.YEAR, 2020)");
|
|
213
|
-
this._renderer.emitLine(".parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)");
|
|
214
|
-
this._renderer.emitLine(".parseDefaulting(ChronoField.DAY_OF_MONTH, 1)");
|
|
215
|
-
this._renderer.emitLine(".toFormatter()");
|
|
216
|
-
this._renderer.emitLine(".withZone(ZoneOffset.UTC);");
|
|
217
|
-
}));
|
|
218
|
-
this._renderer.ensureBlankLine();
|
|
219
|
-
this._renderer.emitBlock("public static OffsetTime parseTimeString(String str)", () => {
|
|
220
|
-
this._renderer.emitLine("return ZonedDateTime.from(Converter.TIME_FORMATTER.parse(str)).toOffsetDateTime().toOffsetTime();");
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
convertStringToDateTime(variable) {
|
|
224
|
-
return [this._className, ".parseDateTimeString(", variable, ")"];
|
|
225
|
-
}
|
|
226
|
-
convertStringToTime(variable) {
|
|
227
|
-
return [this._className, ".parseTimeString(", variable, ")"];
|
|
228
|
-
}
|
|
229
|
-
convertStringToDate(variable) {
|
|
230
|
-
return ["LocalDate.parse(", variable, ")"];
|
|
231
|
-
}
|
|
232
|
-
convertDateTimeToString(variable) {
|
|
233
|
-
return [variable, ".format(java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME)"];
|
|
234
|
-
}
|
|
235
|
-
convertTimeToString(variable) {
|
|
236
|
-
return [variable, ".format(java.time.format.DateTimeFormatter.ISO_OFFSET_TIME)"];
|
|
237
|
-
}
|
|
238
|
-
convertDateToString(variable) {
|
|
239
|
-
return [variable, ".format(java.time.format.DateTimeFormatter.ISO_DATE)"];
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
class JavaLegacyDateTimeProvider extends JavaDateTimeProvider {
|
|
243
|
-
keywords = ["SimpleDateFormat", "Date"];
|
|
244
|
-
dateTimeImports = ["java.util.Date"];
|
|
245
|
-
dateImports = ["java.util.Date"];
|
|
246
|
-
timeImports = ["java.util.Date"];
|
|
247
|
-
converterImports = ["java.util.Date", "java.text.SimpleDateFormat"];
|
|
248
|
-
dateTimeType = "Date";
|
|
249
|
-
dateType = "Date";
|
|
250
|
-
timeType = "Date";
|
|
251
|
-
dateTimeJacksonAnnotations = ['@JsonFormat(pattern = "yyyy-MM-dd\'T\'HH:mm:ssX", timezone = "UTC")'];
|
|
252
|
-
dateJacksonAnnotations = ['@JsonFormat(pattern = "yyyy-MM-dd")'];
|
|
253
|
-
timeJacksonAnnotations = ['@JsonFormat(pattern = "HH:mm:ssX", timezone = "UTC")'];
|
|
254
|
-
emitDateTimeConverters() {
|
|
255
|
-
this._renderer.ensureBlankLine();
|
|
256
|
-
this._renderer.emitLine("private static final String[] DATE_TIME_FORMATS = {");
|
|
257
|
-
this._renderer.indent(() => this._renderer.indent(() => {
|
|
258
|
-
this._renderer.emitLine("\"yyyy-MM-dd'T'HH:mm:ss.SX\",");
|
|
259
|
-
this._renderer.emitLine("\"yyyy-MM-dd'T'HH:mm:ss.S\",");
|
|
260
|
-
this._renderer.emitLine("\"yyyy-MM-dd'T'HH:mm:ssX\",");
|
|
261
|
-
this._renderer.emitLine("\"yyyy-MM-dd'T'HH:mm:ss\",");
|
|
262
|
-
this._renderer.emitLine('"yyyy-MM-dd HH:mm:ss.SX",');
|
|
263
|
-
this._renderer.emitLine('"yyyy-MM-dd HH:mm:ss.S",');
|
|
264
|
-
this._renderer.emitLine('"yyyy-MM-dd HH:mm:ssX",');
|
|
265
|
-
this._renderer.emitLine('"yyyy-MM-dd HH:mm:ss",');
|
|
266
|
-
this._renderer.emitLine('"HH:mm:ss.SZ",');
|
|
267
|
-
this._renderer.emitLine('"HH:mm:ss.S",');
|
|
268
|
-
this._renderer.emitLine('"HH:mm:ssZ",');
|
|
269
|
-
this._renderer.emitLine('"HH:mm:ss",');
|
|
270
|
-
this._renderer.emitLine('"yyyy-MM-dd",');
|
|
271
|
-
}));
|
|
272
|
-
this._renderer.emitLine("};");
|
|
273
|
-
this._renderer.ensureBlankLine();
|
|
274
|
-
this._renderer.emitBlock("public static Date parseAllDateTimeString(String str)", () => {
|
|
275
|
-
this._renderer.emitBlock("for (String format : DATE_TIME_FORMATS)", () => {
|
|
276
|
-
this._renderer.emitIgnoredTryCatchBlock(() => {
|
|
277
|
-
this._renderer.emitLine("return new SimpleDateFormat(format).parse(str);");
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
this._renderer.emitLine("return null;");
|
|
281
|
-
});
|
|
282
|
-
this._renderer.ensureBlankLine();
|
|
283
|
-
this._renderer.emitBlock("public static String serializeDateTime(Date datetime)", () => {
|
|
284
|
-
this._renderer.emitLine("return new SimpleDateFormat(\"yyyy-MM-dd'T'hh:mm:ssZ\").format(datetime);");
|
|
285
|
-
});
|
|
286
|
-
this._renderer.ensureBlankLine();
|
|
287
|
-
this._renderer.emitBlock("public static String serializeDate(Date datetime)", () => {
|
|
288
|
-
this._renderer.emitLine('return new SimpleDateFormat("yyyy-MM-dd").format(datetime);');
|
|
289
|
-
});
|
|
290
|
-
this._renderer.ensureBlankLine();
|
|
291
|
-
this._renderer.emitBlock("public static String serializeTime(Date datetime)", () => {
|
|
292
|
-
this._renderer.emitLine('return new SimpleDateFormat("hh:mm:ssZ").format(datetime);');
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
shouldEmitTimeConverter = false;
|
|
296
|
-
shouldEmitDateConverter = false;
|
|
297
|
-
convertStringToDateTime(variable) {
|
|
298
|
-
return [this._className, ".parseAllDateTimeString(", variable, ")"];
|
|
299
|
-
}
|
|
300
|
-
convertStringToTime(variable) {
|
|
301
|
-
return [this._className, ".parseAllDateTimeString(", variable, ")"];
|
|
302
|
-
}
|
|
303
|
-
convertStringToDate(variable) {
|
|
304
|
-
return [this._className, ".parseAllDateTimeString(", variable, ")"];
|
|
305
|
-
}
|
|
306
|
-
convertDateTimeToString(variable) {
|
|
307
|
-
return [this._className, ".serializeDateTime(", variable, ")"];
|
|
308
|
-
}
|
|
309
|
-
convertTimeToString(variable) {
|
|
310
|
-
return [this._className, ".serializeTime(", variable, ")"];
|
|
311
|
-
}
|
|
312
|
-
convertDateToString(variable) {
|
|
313
|
-
return [this._className, ".serializeDate(", variable, ")"];
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
317
|
-
_options;
|
|
318
|
-
_currentFilename;
|
|
319
|
-
_gettersAndSettersForPropertyName = new Map();
|
|
320
|
-
_haveEmittedLeadingComments = false;
|
|
321
|
-
_dateTimeProvider;
|
|
322
|
-
_converterClassname = "Converter";
|
|
323
|
-
_converterKeywords = [];
|
|
324
|
-
constructor(targetLanguage, renderContext, _options) {
|
|
325
|
-
super(targetLanguage, renderContext);
|
|
326
|
-
this._options = _options;
|
|
327
|
-
switch (_options.dateTimeProvider) {
|
|
328
|
-
default:
|
|
329
|
-
case "java8":
|
|
330
|
-
this._dateTimeProvider = new Java8DateTimeProvider(this, this._converterClassname);
|
|
331
|
-
break;
|
|
332
|
-
case "legacy":
|
|
333
|
-
this._dateTimeProvider = new JavaLegacyDateTimeProvider(this, this._converterClassname);
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
forbiddenNamesForGlobalNamespace() {
|
|
338
|
-
const keywords = [
|
|
339
|
-
...javaKeywords,
|
|
340
|
-
...this._converterKeywords,
|
|
341
|
-
this._converterClassname,
|
|
342
|
-
...this._dateTimeProvider.keywords
|
|
343
|
-
];
|
|
344
|
-
return keywords;
|
|
345
|
-
}
|
|
346
|
-
forbiddenForObjectProperties(_c, _className) {
|
|
347
|
-
return { names: [], includeGlobalForbidden: true };
|
|
348
|
-
}
|
|
349
|
-
makeNamedTypeNamer() {
|
|
350
|
-
return this.getNameStyling("typeNamingFunction");
|
|
351
|
-
}
|
|
352
|
-
namerForObjectProperty() {
|
|
353
|
-
return this.getNameStyling("propertyNamingFunction");
|
|
354
|
-
}
|
|
355
|
-
makeUnionMemberNamer() {
|
|
356
|
-
return this.getNameStyling("propertyNamingFunction");
|
|
357
|
-
}
|
|
358
|
-
makeEnumCaseNamer() {
|
|
359
|
-
return this.getNameStyling("enumCaseNamingFunction");
|
|
360
|
-
}
|
|
361
|
-
unionNeedsName(u) {
|
|
362
|
-
return (0, TypeUtils_1.nullableFromUnion)(u) === null;
|
|
363
|
-
}
|
|
364
|
-
namedTypeToNameForTopLevel(type) {
|
|
365
|
-
// If the top-level type doesn't contain any classes or unions
|
|
366
|
-
// we have to define a class just for the `FromJson` method, in
|
|
367
|
-
// emitFromJsonForTopLevel.
|
|
368
|
-
return (0, TypeUtils_1.directlyReachableSingleNamedType)(type);
|
|
369
|
-
}
|
|
370
|
-
makeNamesForPropertyGetterAndSetter(_c, _className, _p, _jsonName, name) {
|
|
371
|
-
const getterName = new Naming_1.DependencyName(this.getNameStyling("propertyNamingFunction"), name.order, lookup => `get_${lookup(name)}`);
|
|
372
|
-
const setterName = new Naming_1.DependencyName(this.getNameStyling("propertyNamingFunction"), name.order, lookup => `set_${lookup(name)}`);
|
|
373
|
-
return [getterName, setterName];
|
|
374
|
-
}
|
|
375
|
-
makePropertyDependencyNames(c, className, p, jsonName, name) {
|
|
376
|
-
const getterAndSetterNames = this.makeNamesForPropertyGetterAndSetter(c, className, p, jsonName, name);
|
|
377
|
-
this._gettersAndSettersForPropertyName.set(name, getterAndSetterNames);
|
|
378
|
-
return getterAndSetterNames;
|
|
379
|
-
}
|
|
380
|
-
getNameStyling(convention) {
|
|
381
|
-
const styling = {
|
|
382
|
-
typeNamingFunction: (0, Naming_1.funPrefixNamer)("types", n => javaNameStyle(true, false, n, (0, Acronyms_1.acronymStyle)(this._options.acronymStyle))),
|
|
383
|
-
propertyNamingFunction: (0, Naming_1.funPrefixNamer)("properties", n => javaNameStyle(false, false, n, (0, Acronyms_1.acronymStyle)(this._options.acronymStyle))),
|
|
384
|
-
enumCaseNamingFunction: (0, Naming_1.funPrefixNamer)("enum-cases", n => javaNameStyle(true, true, n, (0, Acronyms_1.acronymStyle)(this._options.acronymStyle)))
|
|
385
|
-
};
|
|
386
|
-
return styling[convention];
|
|
387
|
-
}
|
|
388
|
-
fieldOrMethodName(methodName, topLevelName) {
|
|
389
|
-
if (this.topLevels.size === 1) {
|
|
390
|
-
return methodName;
|
|
391
|
-
}
|
|
392
|
-
return [topLevelName, (0, Strings_1.capitalize)(methodName)];
|
|
393
|
-
}
|
|
394
|
-
methodName(prefix, suffix, topLevelName) {
|
|
395
|
-
if (this.topLevels.size === 1) {
|
|
396
|
-
return [prefix, suffix];
|
|
397
|
-
}
|
|
398
|
-
return [prefix, topLevelName, suffix];
|
|
399
|
-
}
|
|
400
|
-
decoderName(topLevelName) {
|
|
401
|
-
return this.fieldOrMethodName("fromJsonString", topLevelName);
|
|
402
|
-
}
|
|
403
|
-
encoderName(topLevelName) {
|
|
404
|
-
return this.fieldOrMethodName("toJsonString", topLevelName);
|
|
405
|
-
}
|
|
406
|
-
readerGetterName(topLevelName) {
|
|
407
|
-
return this.methodName("get", "ObjectReader", topLevelName);
|
|
408
|
-
}
|
|
409
|
-
writerGetterName(topLevelName) {
|
|
410
|
-
return this.methodName("get", "ObjectWriter", topLevelName);
|
|
411
|
-
}
|
|
412
|
-
startFile(basename) {
|
|
413
|
-
(0, Support_1.assert)(this._currentFilename === undefined, "Previous file wasn't finished");
|
|
414
|
-
// FIXME: The filenames should actually be Sourcelikes, too
|
|
415
|
-
this._currentFilename = `${this.sourcelikeToString(basename)}.java`;
|
|
416
|
-
// FIXME: Why is this necessary?
|
|
417
|
-
this.ensureBlankLine();
|
|
418
|
-
if (!this._haveEmittedLeadingComments && this.leadingComments !== undefined) {
|
|
419
|
-
this.emitCommentLines(this.leadingComments);
|
|
420
|
-
this.ensureBlankLine();
|
|
421
|
-
this._haveEmittedLeadingComments = true;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
finishFile() {
|
|
425
|
-
super.finishFile((0, Support_1.defined)(this._currentFilename));
|
|
426
|
-
this._currentFilename = undefined;
|
|
427
|
-
}
|
|
428
|
-
emitPackageAndImports(imports) {
|
|
429
|
-
this.emitLine("package ", this._options.packageName, ";");
|
|
430
|
-
this.ensureBlankLine();
|
|
431
|
-
for (const pkg of imports) {
|
|
432
|
-
this.emitLine("import ", pkg, ";");
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
emitFileHeader(fileName, imports) {
|
|
436
|
-
this.startFile(fileName);
|
|
437
|
-
this.emitPackageAndImports(imports);
|
|
438
|
-
this.ensureBlankLine();
|
|
439
|
-
}
|
|
440
|
-
emitDescriptionBlock(lines) {
|
|
441
|
-
this.emitCommentLines(lines, " * ", "/**", " */");
|
|
442
|
-
}
|
|
443
|
-
emitBlock(line, f) {
|
|
444
|
-
this.emitLine(line, " {");
|
|
445
|
-
this.indent(f);
|
|
446
|
-
this.emitLine("}");
|
|
447
|
-
}
|
|
448
|
-
emitTryCatch(main, handler, exception = "Exception") {
|
|
449
|
-
this.emitLine("try {");
|
|
450
|
-
this.indent(main);
|
|
451
|
-
this.emitLine("} catch (", exception, " ex) {");
|
|
452
|
-
this.indent(handler);
|
|
453
|
-
this.emitLine("}");
|
|
454
|
-
}
|
|
455
|
-
emitIgnoredTryCatchBlock(f) {
|
|
456
|
-
this.emitTryCatch(f, () => this.emitLine("// Ignored"));
|
|
457
|
-
}
|
|
458
|
-
javaType(reference, t, withIssues = false) {
|
|
459
|
-
return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, "Object"), _nullType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.nullTypeIssueAnnotation, "Object"), _boolType => (reference ? "Boolean" : "boolean"), _integerType => (reference ? "Long" : "long"), _doubleType => (reference ? "Double" : "double"), _stringType => "String", arrayType => {
|
|
460
|
-
if (this._options.useList) {
|
|
461
|
-
return ["List<", this.javaType(true, arrayType.items, withIssues), ">"];
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
return [this.javaType(false, arrayType.items, withIssues), "[]"];
|
|
465
|
-
}
|
|
466
|
-
}, classType => this.nameForNamedType(classType), mapType => ["Map<String, ", this.javaType(true, mapType.values, withIssues), ">"], enumType => this.nameForNamedType(enumType), unionType => {
|
|
467
|
-
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
468
|
-
if (nullable !== null)
|
|
469
|
-
return this.javaType(true, nullable, withIssues);
|
|
470
|
-
return this.nameForNamedType(unionType);
|
|
471
|
-
}, transformedStringType => {
|
|
472
|
-
if (transformedStringType.kind === "time") {
|
|
473
|
-
return this._dateTimeProvider.timeType;
|
|
474
|
-
}
|
|
475
|
-
if (transformedStringType.kind === "date") {
|
|
476
|
-
return this._dateTimeProvider.dateType;
|
|
477
|
-
}
|
|
478
|
-
if (transformedStringType.kind === "date-time") {
|
|
479
|
-
return this._dateTimeProvider.dateTimeType;
|
|
480
|
-
}
|
|
481
|
-
if (transformedStringType.kind === "uuid") {
|
|
482
|
-
return "UUID";
|
|
483
|
-
}
|
|
484
|
-
return "String";
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
javaImport(t) {
|
|
488
|
-
return (0, TypeUtils_1.matchType)(t, _anyType => [], _nullType => [], _boolType => [], _integerType => [], _doubleType => [], _stringType => [], arrayType => {
|
|
489
|
-
if (this._options.useList) {
|
|
490
|
-
return [...this.javaImport(arrayType.items), "java.util.List"];
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
return [...this.javaImport(arrayType.items)];
|
|
494
|
-
}
|
|
495
|
-
}, _classType => [], mapType => [...this.javaImport(mapType.values), "java.util.Map"], _enumType => [], unionType => {
|
|
496
|
-
const imports = [];
|
|
497
|
-
unionType.members.forEach(type => this.javaImport(type).forEach(imp => imports.push(imp)));
|
|
498
|
-
return imports;
|
|
499
|
-
}, transformedStringType => {
|
|
500
|
-
if (transformedStringType.kind === "time") {
|
|
501
|
-
return this._dateTimeProvider.timeImports;
|
|
502
|
-
}
|
|
503
|
-
if (transformedStringType.kind === "date") {
|
|
504
|
-
return this._dateTimeProvider.dateImports;
|
|
505
|
-
}
|
|
506
|
-
if (transformedStringType.kind === "date-time") {
|
|
507
|
-
return this._dateTimeProvider.dateTimeImports;
|
|
508
|
-
}
|
|
509
|
-
if (transformedStringType.kind === "uuid") {
|
|
510
|
-
return ["java.util.UUID"];
|
|
511
|
-
}
|
|
512
|
-
return [];
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
javaTypeWithoutGenerics(reference, t) {
|
|
516
|
-
if (t instanceof Type_1.ArrayType) {
|
|
517
|
-
if (this._options.useList) {
|
|
518
|
-
return ["List"];
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
return [this.javaTypeWithoutGenerics(false, t.items), "[]"];
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
else if (t instanceof Type_1.MapType) {
|
|
525
|
-
return "Map";
|
|
526
|
-
}
|
|
527
|
-
else if (t instanceof Type_1.UnionType) {
|
|
528
|
-
const nullable = (0, TypeUtils_1.nullableFromUnion)(t);
|
|
529
|
-
if (nullable !== null)
|
|
530
|
-
return this.javaTypeWithoutGenerics(true, nullable);
|
|
531
|
-
return this.nameForNamedType(t);
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
return this.javaType(reference, t);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
emitClassAttributes(_c, _className) {
|
|
538
|
-
if (this._options.lombok) {
|
|
539
|
-
this.emitLine("@lombok.Data");
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
annotationsForAccessor(_c, _className, _propertyName, _jsonName, _p, _isSetter) {
|
|
543
|
-
return [];
|
|
544
|
-
}
|
|
545
|
-
importsForType(t) {
|
|
546
|
-
if (t instanceof Type_1.ClassType) {
|
|
547
|
-
return [];
|
|
548
|
-
}
|
|
549
|
-
if (t instanceof Type_1.UnionType) {
|
|
550
|
-
return ["java.io.IOException"];
|
|
551
|
-
}
|
|
552
|
-
if (t instanceof Type_1.EnumType) {
|
|
553
|
-
return ["java.io.IOException"];
|
|
554
|
-
}
|
|
555
|
-
return (0, Support_1.assertNever)(t);
|
|
556
|
-
}
|
|
557
|
-
importsForClass(c) {
|
|
558
|
-
const imports = [];
|
|
559
|
-
this.forEachClassProperty(c, "none", (_name, _jsonName, p) => {
|
|
560
|
-
this.javaImport(p.type).forEach(imp => imports.push(imp));
|
|
561
|
-
});
|
|
562
|
-
imports.sort();
|
|
563
|
-
return [...new Set(imports)];
|
|
564
|
-
}
|
|
565
|
-
importsForUnionMembers(u) {
|
|
566
|
-
const imports = [];
|
|
567
|
-
const [, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u);
|
|
568
|
-
this.forEachUnionMember(u, nonNulls, "none", null, (_fieldName, t) => {
|
|
569
|
-
this.javaImport(t).forEach(imp => imports.push(imp));
|
|
570
|
-
});
|
|
571
|
-
imports.sort();
|
|
572
|
-
return [...new Set(imports)];
|
|
573
|
-
}
|
|
574
|
-
emitClassDefinition(c, className) {
|
|
575
|
-
let imports = [...this.importsForType(c), ...this.importsForClass(c)];
|
|
576
|
-
this.emitFileHeader(className, imports);
|
|
577
|
-
this.emitDescription(this.descriptionForType(c));
|
|
578
|
-
this.emitClassAttributes(c, className);
|
|
579
|
-
this.emitBlock(["public class ", className], () => {
|
|
580
|
-
this.forEachClassProperty(c, "none", (name, jsonName, p) => {
|
|
581
|
-
if (this._options.lombok && this._options.lombokCopyAnnotations) {
|
|
582
|
-
const getter = this.annotationsForAccessor(c, className, name, jsonName, p, false);
|
|
583
|
-
const setter = this.annotationsForAccessor(c, className, name, jsonName, p, true);
|
|
584
|
-
if (getter.length !== 0) {
|
|
585
|
-
this.emitLine("@lombok.Getter(onMethod_ = {" + getter.join(", ") + "})");
|
|
586
|
-
}
|
|
587
|
-
if (setter.length !== 0) {
|
|
588
|
-
this.emitLine("@lombok.Setter(onMethod_ = {" + setter.join(", ") + "})");
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
this.emitLine("private ", this.javaType(false, p.type, true), " ", name, ";");
|
|
592
|
-
});
|
|
593
|
-
if (!this._options.lombok) {
|
|
594
|
-
this.forEachClassProperty(c, "leading-and-interposing", (name, jsonName, p) => {
|
|
595
|
-
this.emitDescription(this.descriptionForClassProperty(c, jsonName));
|
|
596
|
-
const [getterName, setterName] = (0, Support_1.defined)(this._gettersAndSettersForPropertyName.get(name));
|
|
597
|
-
const rendered = this.javaType(false, p.type);
|
|
598
|
-
this.annotationsForAccessor(c, className, name, jsonName, p, false).forEach(annotation => this.emitLine(annotation));
|
|
599
|
-
this.emitLine("public ", rendered, " ", getterName, "() { return ", name, "; }");
|
|
600
|
-
this.annotationsForAccessor(c, className, name, jsonName, p, true).forEach(annotation => this.emitLine(annotation));
|
|
601
|
-
this.emitLine("public void ", setterName, "(", rendered, " value) { this.", name, " = value; }");
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
this.finishFile();
|
|
606
|
-
}
|
|
607
|
-
unionField(u, t, withIssues = false) {
|
|
608
|
-
const fieldType = this.javaType(true, t, withIssues);
|
|
609
|
-
// FIXME: "Value" should be part of the name.
|
|
610
|
-
const fieldName = [this.nameForUnionMember(u, t), "Value"];
|
|
611
|
-
return { fieldType, fieldName };
|
|
612
|
-
}
|
|
613
|
-
emitUnionAttributes(_u, _unionName) {
|
|
614
|
-
// empty
|
|
615
|
-
}
|
|
616
|
-
emitUnionSerializer(_u, _unionName) {
|
|
617
|
-
// empty
|
|
618
|
-
}
|
|
619
|
-
emitUnionDefinition(u, unionName) {
|
|
620
|
-
const imports = [...this.importsForType(u), ...this.importsForUnionMembers(u)];
|
|
621
|
-
this.emitFileHeader(unionName, imports);
|
|
622
|
-
this.emitDescription(this.descriptionForType(u));
|
|
623
|
-
const [, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u);
|
|
624
|
-
this.emitUnionAttributes(u, unionName);
|
|
625
|
-
this.emitBlock(["public class ", unionName], () => {
|
|
626
|
-
for (const t of nonNulls) {
|
|
627
|
-
const { fieldType, fieldName } = this.unionField(u, t, true);
|
|
628
|
-
this.emitLine("public ", fieldType, " ", fieldName, ";");
|
|
629
|
-
}
|
|
630
|
-
this.emitUnionSerializer(u, unionName);
|
|
631
|
-
});
|
|
632
|
-
this.finishFile();
|
|
633
|
-
}
|
|
634
|
-
emitEnumSerializationAttributes(_e) {
|
|
635
|
-
// Empty
|
|
636
|
-
}
|
|
637
|
-
emitEnumDeserializationAttributes(_e) {
|
|
638
|
-
// Empty
|
|
639
|
-
}
|
|
640
|
-
emitEnumDefinition(e, enumName) {
|
|
641
|
-
this.emitFileHeader(enumName, this.importsForType(e));
|
|
642
|
-
this.emitDescription(this.descriptionForType(e));
|
|
643
|
-
const caseNames = [];
|
|
644
|
-
this.forEachEnumCase(e, "none", name => {
|
|
645
|
-
if (caseNames.length > 0)
|
|
646
|
-
caseNames.push(", ");
|
|
647
|
-
caseNames.push(name);
|
|
648
|
-
});
|
|
649
|
-
caseNames.push(";");
|
|
650
|
-
this.emitBlock(["public enum ", enumName], () => {
|
|
651
|
-
this.emitLine(caseNames);
|
|
652
|
-
this.ensureBlankLine();
|
|
653
|
-
this.emitEnumSerializationAttributes(e);
|
|
654
|
-
this.emitBlock("public String toValue()", () => {
|
|
655
|
-
this.emitLine("switch (this) {");
|
|
656
|
-
this.indent(() => {
|
|
657
|
-
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
658
|
-
this.emitLine("case ", name, ': return "', (0, exports.stringEscape)(jsonName), '";');
|
|
659
|
-
});
|
|
660
|
-
});
|
|
661
|
-
this.emitLine("}");
|
|
662
|
-
this.emitLine("return null;");
|
|
663
|
-
});
|
|
664
|
-
this.ensureBlankLine();
|
|
665
|
-
this.emitEnumDeserializationAttributes(e);
|
|
666
|
-
this.emitBlock(["public static ", enumName, " forValue(String value) throws IOException"], () => {
|
|
667
|
-
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
668
|
-
this.emitLine('if (value.equals("', (0, exports.stringEscape)(jsonName), '")) return ', name, ";");
|
|
669
|
-
});
|
|
670
|
-
this.emitLine('throw new IOException("Cannot deserialize ', enumName, '");');
|
|
671
|
-
});
|
|
672
|
-
});
|
|
673
|
-
this.finishFile();
|
|
674
|
-
}
|
|
675
|
-
emitSourceStructure() {
|
|
676
|
-
this.forEachNamedType("leading-and-interposing", (c, n) => this.emitClassDefinition(c, n), (e, n) => this.emitEnumDefinition(e, n), (u, n) => this.emitUnionDefinition(u, n));
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
exports.JavaRenderer = JavaRenderer;
|
|
680
|
-
class JacksonRenderer extends JavaRenderer {
|
|
681
|
-
constructor(targetLanguage, renderContext, options) {
|
|
682
|
-
super(targetLanguage, renderContext, options);
|
|
683
|
-
}
|
|
684
|
-
_converterKeywords = [
|
|
685
|
-
"JsonProperty",
|
|
686
|
-
"JsonDeserialize",
|
|
687
|
-
"JsonDeserializer",
|
|
688
|
-
"JsonSerialize",
|
|
689
|
-
"JsonSerializer",
|
|
690
|
-
"JsonParser",
|
|
691
|
-
"JsonProcessingException",
|
|
692
|
-
"DeserializationContext",
|
|
693
|
-
"SerializerProvider"
|
|
694
|
-
];
|
|
695
|
-
emitClassAttributes(c, _className) {
|
|
696
|
-
if (c.getProperties().size === 0)
|
|
697
|
-
this.emitLine("@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.NONE)");
|
|
698
|
-
super.emitClassAttributes(c, _className);
|
|
699
|
-
}
|
|
700
|
-
annotationsForAccessor(_c, _className, _propertyName, jsonName, p, _isSetter) {
|
|
701
|
-
const superAnnotations = super.annotationsForAccessor(_c, _className, _propertyName, jsonName, p, _isSetter);
|
|
702
|
-
const annotations = ['@JsonProperty("' + (0, exports.stringEscape)(jsonName) + '")'];
|
|
703
|
-
switch (p.type.kind) {
|
|
704
|
-
case "date-time":
|
|
705
|
-
this._dateTimeProvider.dateTimeJacksonAnnotations.forEach(annotation => annotations.push(annotation));
|
|
706
|
-
break;
|
|
707
|
-
case "date":
|
|
708
|
-
this._dateTimeProvider.dateJacksonAnnotations.forEach(annotation => annotations.push(annotation));
|
|
709
|
-
break;
|
|
710
|
-
case "time":
|
|
711
|
-
this._dateTimeProvider.timeJacksonAnnotations.forEach(annotation => annotations.push(annotation));
|
|
712
|
-
break;
|
|
713
|
-
default:
|
|
714
|
-
break;
|
|
715
|
-
}
|
|
716
|
-
return [...superAnnotations, ...annotations];
|
|
717
|
-
}
|
|
718
|
-
importsForType(t) {
|
|
719
|
-
if (t instanceof Type_1.ClassType) {
|
|
720
|
-
const imports = super.importsForType(t);
|
|
721
|
-
imports.push("com.fasterxml.jackson.annotation.*");
|
|
722
|
-
return imports;
|
|
723
|
-
}
|
|
724
|
-
if (t instanceof Type_1.UnionType) {
|
|
725
|
-
const imports = super.importsForType(t);
|
|
726
|
-
imports.push("java.io.IOException", "com.fasterxml.jackson.core.*", "com.fasterxml.jackson.databind.*", "com.fasterxml.jackson.databind.annotation.*");
|
|
727
|
-
if (this._options.useList) {
|
|
728
|
-
imports.push("com.fasterxml.jackson.core.type.*");
|
|
729
|
-
}
|
|
730
|
-
return imports;
|
|
731
|
-
}
|
|
732
|
-
if (t instanceof Type_1.EnumType) {
|
|
733
|
-
const imports = super.importsForType(t);
|
|
734
|
-
imports.push("com.fasterxml.jackson.annotation.*");
|
|
735
|
-
return imports;
|
|
736
|
-
}
|
|
737
|
-
return (0, Support_1.assertNever)(t);
|
|
738
|
-
}
|
|
739
|
-
emitUnionAttributes(_u, unionName) {
|
|
740
|
-
this.emitLine("@JsonDeserialize(using = ", unionName, ".Deserializer.class)");
|
|
741
|
-
this.emitLine("@JsonSerialize(using = ", unionName, ".Serializer.class)");
|
|
742
|
-
}
|
|
743
|
-
emitUnionSerializer(u, unionName) {
|
|
744
|
-
const stringBasedObjects = ["uuid", "time", "date", "date-time"];
|
|
745
|
-
const tokenCase = (tokenType) => {
|
|
746
|
-
this.emitLine("case ", tokenType, ":");
|
|
747
|
-
};
|
|
748
|
-
const emitNullDeserializer = () => {
|
|
749
|
-
this.indent(() => {
|
|
750
|
-
tokenCase("VALUE_NULL");
|
|
751
|
-
this.indent(() => this.emitLine("break;"));
|
|
752
|
-
});
|
|
753
|
-
};
|
|
754
|
-
const emitDeserializerCodeForStringObjects = (fieldName, kind, parseFrom) => {
|
|
755
|
-
switch (kind) {
|
|
756
|
-
case "date":
|
|
757
|
-
this.emitLine("value.", fieldName, " = ", this._dateTimeProvider.convertStringToDate(parseFrom), ";");
|
|
758
|
-
break;
|
|
759
|
-
case "time":
|
|
760
|
-
this.emitLine("value.", fieldName, " = ", this._dateTimeProvider.convertStringToTime(parseFrom), ";");
|
|
761
|
-
break;
|
|
762
|
-
case "date-time":
|
|
763
|
-
this.emitLine("value.", fieldName, " = ", this._dateTimeProvider.convertStringToDateTime(parseFrom), ";");
|
|
764
|
-
break;
|
|
765
|
-
case "uuid":
|
|
766
|
-
this.emitLine("value.", fieldName, " = UUID.fromString(", parseFrom, ");");
|
|
767
|
-
break;
|
|
768
|
-
default:
|
|
769
|
-
return (0, Support_1.panic)("Requested type isnt an object!");
|
|
770
|
-
}
|
|
771
|
-
};
|
|
772
|
-
const emitDeserializeType = (t, variableFieldName = "") => {
|
|
773
|
-
const { fieldName } = this.unionField(u, t);
|
|
774
|
-
const rendered = this.javaTypeWithoutGenerics(true, t);
|
|
775
|
-
if (this._options.useList && t instanceof Type_1.ArrayType) {
|
|
776
|
-
this.emitLine("value.", fieldName, " = jsonParser.readValueAs(new TypeReference<", rendered, ">() {});");
|
|
777
|
-
}
|
|
778
|
-
else if (stringBasedObjects.some(stringBasedTypeKind => t.kind === stringBasedTypeKind)) {
|
|
779
|
-
emitDeserializerCodeForStringObjects(fieldName, t.kind, variableFieldName);
|
|
780
|
-
}
|
|
781
|
-
else if (t.kind === "string") {
|
|
782
|
-
this.emitLine("value.", fieldName, " = ", variableFieldName, ";");
|
|
783
|
-
}
|
|
784
|
-
else if (t.kind === "enum") {
|
|
785
|
-
const { fieldType } = this.unionField(u, t, true);
|
|
786
|
-
this.emitLine("value.", fieldName, " = ", fieldType, ".forValue(", variableFieldName, ");");
|
|
787
|
-
}
|
|
788
|
-
else {
|
|
789
|
-
this.emitLine("value.", fieldName, " = jsonParser.readValueAs(", rendered, ".class);");
|
|
790
|
-
}
|
|
791
|
-
};
|
|
792
|
-
const emitDeserializer = (tokenTypes, kind) => {
|
|
793
|
-
const t = u.findMember(kind);
|
|
794
|
-
if (t === undefined)
|
|
795
|
-
return;
|
|
796
|
-
this.indent(() => {
|
|
797
|
-
for (const tokenType of tokenTypes) {
|
|
798
|
-
tokenCase(tokenType);
|
|
799
|
-
}
|
|
800
|
-
this.indent(() => {
|
|
801
|
-
emitDeserializeType(t);
|
|
802
|
-
this.emitLine("break;");
|
|
803
|
-
});
|
|
804
|
-
});
|
|
805
|
-
};
|
|
806
|
-
const emitStringDeserializer = () => {
|
|
807
|
-
const enumType = u.findMember("enum");
|
|
808
|
-
const stringType = u.findMember("string");
|
|
809
|
-
if (stringBasedObjects.every(kind => u.findMember(kind) === undefined) &&
|
|
810
|
-
stringType === undefined &&
|
|
811
|
-
enumType === undefined)
|
|
812
|
-
return;
|
|
813
|
-
this.indent(() => {
|
|
814
|
-
tokenCase("VALUE_STRING");
|
|
815
|
-
this.indent(() => {
|
|
816
|
-
const fromVariable = "string";
|
|
817
|
-
this.emitLine("String " + fromVariable + " = jsonParser.readValueAs(String.class);");
|
|
818
|
-
stringBasedObjects.forEach(kind => {
|
|
819
|
-
const type = u.findMember(kind);
|
|
820
|
-
if (type !== undefined) {
|
|
821
|
-
this.emitIgnoredTryCatchBlock(() => {
|
|
822
|
-
emitDeserializeType(type, fromVariable);
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
});
|
|
826
|
-
if (enumType !== undefined) {
|
|
827
|
-
this.emitIgnoredTryCatchBlock(() => {
|
|
828
|
-
emitDeserializeType(enumType, fromVariable);
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
// String should be the last one if exists, because it cannot fail, unlike the parsers.
|
|
832
|
-
if (stringType !== undefined) {
|
|
833
|
-
emitDeserializeType(stringType, fromVariable);
|
|
834
|
-
}
|
|
835
|
-
this.emitLine("break;");
|
|
836
|
-
});
|
|
837
|
-
});
|
|
838
|
-
};
|
|
839
|
-
const emitNumberDeserializer = () => {
|
|
840
|
-
const integerType = u.findMember("integer");
|
|
841
|
-
const doubleType = u.findMember("double");
|
|
842
|
-
if (doubleType === undefined && integerType === undefined)
|
|
843
|
-
return;
|
|
844
|
-
this.indent(() => {
|
|
845
|
-
tokenCase("VALUE_NUMBER_INT");
|
|
846
|
-
if (integerType !== undefined) {
|
|
847
|
-
this.indent(() => {
|
|
848
|
-
emitDeserializeType(integerType);
|
|
849
|
-
this.emitLine("break;");
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
if (doubleType !== undefined) {
|
|
853
|
-
tokenCase("VALUE_NUMBER_FLOAT");
|
|
854
|
-
this.indent(() => {
|
|
855
|
-
emitDeserializeType(doubleType);
|
|
856
|
-
this.emitLine("break;");
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
});
|
|
860
|
-
};
|
|
861
|
-
const customObjectSerializer = ["time", "date", "date-time"];
|
|
862
|
-
const serializerCodeForType = (type, fieldName) => {
|
|
863
|
-
switch (type.kind) {
|
|
864
|
-
case "date":
|
|
865
|
-
return this._dateTimeProvider.convertDateToString(fieldName);
|
|
866
|
-
case "time":
|
|
867
|
-
return this._dateTimeProvider.convertTimeToString(fieldName);
|
|
868
|
-
case "date-time":
|
|
869
|
-
return this._dateTimeProvider.convertDateTimeToString(fieldName);
|
|
870
|
-
default:
|
|
871
|
-
return (0, Support_1.panic)("Requested type doesn't have custom serializer code!");
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
const emitSerializeType = (t) => {
|
|
875
|
-
let { fieldName } = this.unionField(u, t, true);
|
|
876
|
-
this.emitBlock(["if (obj.", fieldName, " != null)"], () => {
|
|
877
|
-
if (customObjectSerializer.some(customSerializerType => t.kind === customSerializerType)) {
|
|
878
|
-
this.emitLine("jsonGenerator.writeObject(", serializerCodeForType(t, ["obj.", fieldName]), ");");
|
|
879
|
-
}
|
|
880
|
-
else {
|
|
881
|
-
this.emitLine("jsonGenerator.writeObject(obj.", fieldName, ");");
|
|
882
|
-
}
|
|
883
|
-
this.emitLine("return;");
|
|
884
|
-
});
|
|
885
|
-
};
|
|
886
|
-
const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u);
|
|
887
|
-
this.ensureBlankLine();
|
|
888
|
-
this.emitBlock(["static class Deserializer extends JsonDeserializer<", unionName, ">"], () => {
|
|
889
|
-
this.emitLine("@Override");
|
|
890
|
-
this.emitBlock([
|
|
891
|
-
"public ",
|
|
892
|
-
unionName,
|
|
893
|
-
" deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException"
|
|
894
|
-
], () => {
|
|
895
|
-
this.emitLine(unionName, " value = new ", unionName, "();");
|
|
896
|
-
this.emitLine("switch (jsonParser.currentToken()) {");
|
|
897
|
-
if (maybeNull !== null)
|
|
898
|
-
emitNullDeserializer();
|
|
899
|
-
emitNumberDeserializer();
|
|
900
|
-
emitDeserializer(["VALUE_TRUE", "VALUE_FALSE"], "bool");
|
|
901
|
-
emitStringDeserializer();
|
|
902
|
-
emitDeserializer(["START_ARRAY"], "array");
|
|
903
|
-
emitDeserializer(["START_OBJECT"], "class");
|
|
904
|
-
emitDeserializer(["START_OBJECT"], "map");
|
|
905
|
-
this.indent(() => this.emitLine('default: throw new IOException("Cannot deserialize ', unionName, '");'));
|
|
906
|
-
this.emitLine("}");
|
|
907
|
-
this.emitLine("return value;");
|
|
908
|
-
});
|
|
909
|
-
});
|
|
910
|
-
this.ensureBlankLine();
|
|
911
|
-
this.emitBlock(["static class Serializer extends JsonSerializer<", unionName, ">"], () => {
|
|
912
|
-
this.emitLine("@Override");
|
|
913
|
-
this.emitBlock([
|
|
914
|
-
"public void serialize(",
|
|
915
|
-
unionName,
|
|
916
|
-
" obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException"
|
|
917
|
-
], () => {
|
|
918
|
-
for (const t of nonNulls) {
|
|
919
|
-
emitSerializeType(t);
|
|
920
|
-
}
|
|
921
|
-
if (maybeNull !== null) {
|
|
922
|
-
this.emitLine("jsonGenerator.writeNull();");
|
|
923
|
-
}
|
|
924
|
-
else {
|
|
925
|
-
this.emitLine('throw new IOException("', unionName, ' must not be null");');
|
|
926
|
-
}
|
|
927
|
-
});
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
emitEnumSerializationAttributes(_e) {
|
|
931
|
-
this.emitLine("@JsonValue");
|
|
932
|
-
}
|
|
933
|
-
emitEnumDeserializationAttributes(_e) {
|
|
934
|
-
this.emitLine("@JsonCreator");
|
|
935
|
-
}
|
|
936
|
-
emitOffsetDateTimeConverterModule() {
|
|
937
|
-
this.emitLine("SimpleModule module = new SimpleModule();");
|
|
938
|
-
if (this._dateTimeProvider.shouldEmitDateTimeConverter) {
|
|
939
|
-
this.emitLine("module.addDeserializer(", this._dateTimeProvider.dateTimeType, ".class, new JsonDeserializer<", this._dateTimeProvider.dateTimeType, ">() {");
|
|
940
|
-
this.indent(() => {
|
|
941
|
-
this.emitLine("@Override");
|
|
942
|
-
this.emitBlock([
|
|
943
|
-
"public ",
|
|
944
|
-
this._dateTimeProvider.dateTimeType,
|
|
945
|
-
" deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) ",
|
|
946
|
-
"throws IOException, JsonProcessingException"
|
|
947
|
-
], () => {
|
|
948
|
-
this.emitLine("String value = jsonParser.getText();");
|
|
949
|
-
this.emitLine("return ", this._dateTimeProvider.convertStringToDateTime("value"), ";");
|
|
950
|
-
});
|
|
951
|
-
});
|
|
952
|
-
this.emitLine("});");
|
|
953
|
-
}
|
|
954
|
-
if (!this._dateTimeProvider.shouldEmitTimeConverter) {
|
|
955
|
-
this.emitLine("module.addDeserializer(", this._dateTimeProvider.timeType, ".class, new JsonDeserializer<", this._dateTimeProvider.timeType, ">() {");
|
|
956
|
-
this.indent(() => {
|
|
957
|
-
this.emitLine("@Override");
|
|
958
|
-
this.emitBlock([
|
|
959
|
-
"public ",
|
|
960
|
-
this._dateTimeProvider.timeType,
|
|
961
|
-
" deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) ",
|
|
962
|
-
"throws IOException, JsonProcessingException"
|
|
963
|
-
], () => {
|
|
964
|
-
this.emitLine("String value = jsonParser.getText();");
|
|
965
|
-
this.emitLine("return ", this._dateTimeProvider.convertStringToTime("value"), ";");
|
|
966
|
-
});
|
|
967
|
-
});
|
|
968
|
-
this.emitLine("});");
|
|
969
|
-
}
|
|
970
|
-
if (!this._dateTimeProvider.shouldEmitDateConverter) {
|
|
971
|
-
this.emitLine("module.addDeserializer(", this._dateTimeProvider.dateType, ".class, new JsonDeserializer<", this._dateTimeProvider.dateType, ">() {");
|
|
972
|
-
this.indent(() => {
|
|
973
|
-
this.emitLine("@Override");
|
|
974
|
-
this.emitBlock([
|
|
975
|
-
"public ",
|
|
976
|
-
this._dateTimeProvider.dateType,
|
|
977
|
-
" deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) ",
|
|
978
|
-
"throws IOException, JsonProcessingException"
|
|
979
|
-
], () => {
|
|
980
|
-
this.emitLine("String value = jsonParser.getText();");
|
|
981
|
-
this.emitLine("return ", this._dateTimeProvider.convertStringToDate("value"), ";");
|
|
982
|
-
});
|
|
983
|
-
});
|
|
984
|
-
this.emitLine("});");
|
|
985
|
-
}
|
|
986
|
-
this.emitLine("mapper.registerModule(module);");
|
|
987
|
-
}
|
|
988
|
-
emitConverterClass() {
|
|
989
|
-
this.startFile(this._converterClassname);
|
|
990
|
-
this.emitCommentLines([
|
|
991
|
-
"To use this code, add the following Maven dependency to your project:",
|
|
992
|
-
"",
|
|
993
|
-
this._options.lombok ? " org.projectlombok : lombok : 1.18.2" : "",
|
|
994
|
-
" com.fasterxml.jackson.core : jackson-databind : 2.9.0",
|
|
995
|
-
this._options.dateTimeProvider === "java8"
|
|
996
|
-
? " com.fasterxml.jackson.datatype : jackson-datatype-jsr310 : 2.9.0"
|
|
997
|
-
: "",
|
|
998
|
-
"",
|
|
999
|
-
"Import this package:",
|
|
1000
|
-
""
|
|
1001
|
-
]);
|
|
1002
|
-
this.emitLine("// import ", this._options.packageName, ".Converter;");
|
|
1003
|
-
this.emitMultiline(`//
|
|
1004
|
-
// Then you can deserialize a JSON string with
|
|
1005
|
-
//`);
|
|
1006
|
-
this.forEachTopLevel("none", (t, name) => {
|
|
1007
|
-
this.emitLine("// ", this.javaType(false, t), " data = Converter.", this.decoderName(name), "(jsonString);");
|
|
1008
|
-
});
|
|
1009
|
-
this.ensureBlankLine();
|
|
1010
|
-
const imports = [
|
|
1011
|
-
"java.io.IOException",
|
|
1012
|
-
"com.fasterxml.jackson.databind.*",
|
|
1013
|
-
"com.fasterxml.jackson.databind.module.SimpleModule",
|
|
1014
|
-
"com.fasterxml.jackson.core.JsonParser",
|
|
1015
|
-
"com.fasterxml.jackson.core.JsonProcessingException",
|
|
1016
|
-
"java.util.*"
|
|
1017
|
-
].concat(this._dateTimeProvider.converterImports);
|
|
1018
|
-
this.emitPackageAndImports(imports);
|
|
1019
|
-
this.ensureBlankLine();
|
|
1020
|
-
this.emitBlock(["public class Converter"], () => {
|
|
1021
|
-
this.emitLine("// Date-time helpers");
|
|
1022
|
-
this._dateTimeProvider.emitDateTimeConverters();
|
|
1023
|
-
this.emitLine("// Serialize/deserialize helpers");
|
|
1024
|
-
this.forEachTopLevel("leading-and-interposing", (topLevelType, topLevelName) => {
|
|
1025
|
-
const topLevelTypeRendered = this.javaType(false, topLevelType);
|
|
1026
|
-
this.emitBlock([
|
|
1027
|
-
"public static ",
|
|
1028
|
-
topLevelTypeRendered,
|
|
1029
|
-
" ",
|
|
1030
|
-
this.decoderName(topLevelName),
|
|
1031
|
-
"(String json) throws IOException"
|
|
1032
|
-
], () => {
|
|
1033
|
-
this.emitLine("return ", this.readerGetterName(topLevelName), "().readValue(json);");
|
|
1034
|
-
});
|
|
1035
|
-
this.ensureBlankLine();
|
|
1036
|
-
this.emitBlock([
|
|
1037
|
-
"public static String ",
|
|
1038
|
-
this.encoderName(topLevelName),
|
|
1039
|
-
"(",
|
|
1040
|
-
topLevelTypeRendered,
|
|
1041
|
-
" obj) throws JsonProcessingException"
|
|
1042
|
-
], () => {
|
|
1043
|
-
this.emitLine("return ", this.writerGetterName(topLevelName), "().writeValueAsString(obj);");
|
|
1044
|
-
});
|
|
1045
|
-
});
|
|
1046
|
-
this.forEachTopLevel("leading-and-interposing", (topLevelType, topLevelName) => {
|
|
1047
|
-
const readerName = this.fieldOrMethodName("reader", topLevelName);
|
|
1048
|
-
const writerName = this.fieldOrMethodName("writer", topLevelName);
|
|
1049
|
-
this.emitLine("private static ObjectReader ", readerName, ";");
|
|
1050
|
-
this.emitLine("private static ObjectWriter ", writerName, ";");
|
|
1051
|
-
this.ensureBlankLine();
|
|
1052
|
-
this.emitBlock(["private static void ", this.methodName("instantiate", "Mapper", topLevelName), "()"], () => {
|
|
1053
|
-
const renderedForClass = this.javaTypeWithoutGenerics(false, topLevelType);
|
|
1054
|
-
this.emitLine("ObjectMapper mapper = new ObjectMapper();");
|
|
1055
|
-
this.emitLine("mapper.findAndRegisterModules();");
|
|
1056
|
-
this.emitLine("mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);");
|
|
1057
|
-
this.emitLine("mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);");
|
|
1058
|
-
this.emitOffsetDateTimeConverterModule();
|
|
1059
|
-
this.emitLine(readerName, " = mapper.readerFor(", renderedForClass, ".class);");
|
|
1060
|
-
this.emitLine(writerName, " = mapper.writerFor(", renderedForClass, ".class);");
|
|
1061
|
-
});
|
|
1062
|
-
this.ensureBlankLine();
|
|
1063
|
-
this.emitBlock(["private static ObjectReader ", this.readerGetterName(topLevelName), "()"], () => {
|
|
1064
|
-
this.emitLine("if (", readerName, " == null) ", this.methodName("instantiate", "Mapper", topLevelName), "();");
|
|
1065
|
-
this.emitLine("return ", readerName, ";");
|
|
1066
|
-
});
|
|
1067
|
-
this.ensureBlankLine();
|
|
1068
|
-
this.emitBlock(["private static ObjectWriter ", this.writerGetterName(topLevelName), "()"], () => {
|
|
1069
|
-
this.emitLine("if (", writerName, " == null) ", this.methodName("instantiate", "Mapper", topLevelName), "();");
|
|
1070
|
-
this.emitLine("return ", writerName, ";");
|
|
1071
|
-
});
|
|
1072
|
-
});
|
|
1073
|
-
});
|
|
1074
|
-
this.finishFile();
|
|
1075
|
-
}
|
|
1076
|
-
emitSourceStructure() {
|
|
1077
|
-
this.emitConverterClass();
|
|
1078
|
-
super.emitSourceStructure();
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
exports.JacksonRenderer = JacksonRenderer;
|