-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathRestrictionQueryResponseIncludedItem.java
221 lines (200 loc) · 8.7 KB
/
RestrictionQueryResponseIncludedItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-Present Datadog, Inc.
*/
package com.datadog.api.client.v2.model;
import com.datadog.api.client.AbstractOpenApiSchema;
import com.datadog.api.client.JSON;
import com.datadog.api.client.UnparsedObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import jakarta.ws.rs.core.GenericType;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@jakarta.annotation.Generated(
value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator")
@JsonDeserialize(
using =
RestrictionQueryResponseIncludedItem.RestrictionQueryResponseIncludedItemDeserializer.class)
@JsonSerialize(
using =
RestrictionQueryResponseIncludedItem.RestrictionQueryResponseIncludedItemSerializer.class)
public class RestrictionQueryResponseIncludedItem extends AbstractOpenApiSchema {
private static final Logger log =
Logger.getLogger(RestrictionQueryResponseIncludedItem.class.getName());
@JsonIgnore public boolean unparsed = false;
public static class RestrictionQueryResponseIncludedItemSerializer
extends StdSerializer<RestrictionQueryResponseIncludedItem> {
public RestrictionQueryResponseIncludedItemSerializer(
Class<RestrictionQueryResponseIncludedItem> t) {
super(t);
}
public RestrictionQueryResponseIncludedItemSerializer() {
this(null);
}
@Override
public void serialize(
RestrictionQueryResponseIncludedItem value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeObject(value.getActualInstance());
}
}
public static class RestrictionQueryResponseIncludedItemDeserializer
extends StdDeserializer<RestrictionQueryResponseIncludedItem> {
public RestrictionQueryResponseIncludedItemDeserializer() {
this(RestrictionQueryResponseIncludedItem.class);
}
public RestrictionQueryResponseIncludedItemDeserializer(Class<?> vc) {
super(vc);
}
@Override
public RestrictionQueryResponseIncludedItem deserialize(
JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode tree = jp.readValueAsTree();
Object deserialized = null;
Object tmp = null;
boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS);
int match = 0;
JsonToken token = tree.traverse(jp.getCodec()).nextToken();
// deserialize RestrictionQueryRole
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
if (RestrictionQueryRole.class.equals(Integer.class)
|| RestrictionQueryRole.class.equals(Long.class)
|| RestrictionQueryRole.class.equals(Float.class)
|| RestrictionQueryRole.class.equals(Double.class)
|| RestrictionQueryRole.class.equals(Boolean.class)
|| RestrictionQueryRole.class.equals(String.class)) {
attemptParsing = typeCoercion;
if (!attemptParsing) {
attemptParsing |=
((RestrictionQueryRole.class.equals(Integer.class)
|| RestrictionQueryRole.class.equals(Long.class))
&& token == JsonToken.VALUE_NUMBER_INT);
attemptParsing |=
((RestrictionQueryRole.class.equals(Float.class)
|| RestrictionQueryRole.class.equals(Double.class))
&& (token == JsonToken.VALUE_NUMBER_FLOAT
|| token == JsonToken.VALUE_NUMBER_INT));
attemptParsing |=
(RestrictionQueryRole.class.equals(Boolean.class)
&& (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
attemptParsing |=
(RestrictionQueryRole.class.equals(String.class)
&& token == JsonToken.VALUE_STRING);
}
}
if (attemptParsing) {
tmp = tree.traverse(jp.getCodec()).readValueAs(RestrictionQueryRole.class);
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
if (!((RestrictionQueryRole) tmp).unparsed) {
deserialized = tmp;
match++;
}
log.log(Level.FINER, "Input data matches schema 'RestrictionQueryRole'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'RestrictionQueryRole'", e);
}
RestrictionQueryResponseIncludedItem ret = new RestrictionQueryResponseIncludedItem();
if (match == 1) {
ret.setActualInstance(deserialized);
} else {
Map<String, Object> res =
new ObjectMapper()
.readValue(
tree.traverse(jp.getCodec()).readValueAsTree().toString(),
new TypeReference<Map<String, Object>>() {});
ret.setActualInstance(new UnparsedObject(res));
}
return ret;
}
/** Handle deserialization of the 'null' value. */
@Override
public RestrictionQueryResponseIncludedItem getNullValue(DeserializationContext ctxt)
throws JsonMappingException {
throw new JsonMappingException(
ctxt.getParser(), "RestrictionQueryResponseIncludedItem cannot be null");
}
}
// store a list of schema names defined in oneOf
public static final Map<String, GenericType> schemas = new HashMap<String, GenericType>();
public RestrictionQueryResponseIncludedItem() {
super("oneOf", Boolean.FALSE);
}
public RestrictionQueryResponseIncludedItem(RestrictionQueryRole o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
static {
schemas.put("RestrictionQueryRole", new GenericType<RestrictionQueryRole>() {});
JSON.registerDescendants(
RestrictionQueryResponseIncludedItem.class, Collections.unmodifiableMap(schemas));
}
@Override
public Map<String, GenericType> getSchemas() {
return RestrictionQueryResponseIncludedItem.schemas;
}
/**
* Set the instance that matches the oneOf child schema, check the instance parameter is valid
* against the oneOf child schemas: RestrictionQueryRole
*
* <p>It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a
* composed schema (allOf, anyOf, oneOf).
*/
@Override
public void setActualInstance(Object instance) {
if (JSON.isInstanceOf(RestrictionQueryRole.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}
if (JSON.isInstanceOf(UnparsedObject.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}
throw new RuntimeException("Invalid instance type. Must be RestrictionQueryRole");
}
/**
* Get the actual instance, which can be the following: RestrictionQueryRole
*
* @return The actual instance (RestrictionQueryRole)
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}
/**
* Get the actual instance of `RestrictionQueryRole`. If the actual instance is not
* `RestrictionQueryRole`, the ClassCastException will be thrown.
*
* @return The actual instance of `RestrictionQueryRole`
* @throws ClassCastException if the instance is not `RestrictionQueryRole`
*/
public RestrictionQueryRole getRestrictionQueryRole() throws ClassCastException {
return (RestrictionQueryRole) super.getActualInstance();
}
}