• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Adyen / adyen-java-api-library / #2727

23 Oct 2023 09:13AM UTC coverage: 12.553%. First build
#2727

push

web-flow
Merge 2e56caa5d into c99ba89a9

339 of 339 new or added lines in 5 files covered. (100.0%)

11880 of 94636 relevant lines covered (12.55%)

0.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.94
/src/main/java/com/adyen/model/checkout/DonationPaymentMethod.java
1
/*
2
 * Adyen Checkout API
3
 *
4
 * The version of the OpenAPI document: 70
5
 * 
6
 *
7
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
8
 * https://openapi-generator.tech
9
 * Do not edit the class manually.
10
 */
11

12

13
package com.adyen.model.checkout;
14

15
import java.util.Objects;
16
import java.util.Arrays;
17
import java.util.Map;
18
import java.util.HashMap;
19
import com.adyen.model.checkout.ApplePayDetails;
20
import com.adyen.model.checkout.CardDetails;
21
import com.adyen.model.checkout.GooglePayDetails;
22
import com.adyen.model.checkout.IdealDetails;
23
import com.adyen.model.checkout.PayWithGoogleDetails;
24
import com.fasterxml.jackson.annotation.JsonInclude;
25
import com.fasterxml.jackson.annotation.JsonProperty;
26
import com.fasterxml.jackson.annotation.JsonCreator;
27
import com.fasterxml.jackson.annotation.JsonTypeName;
28
import com.fasterxml.jackson.annotation.JsonValue;
29
import io.swagger.annotations.ApiModel;
30
import io.swagger.annotations.ApiModelProperty;
31
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
32
import com.fasterxml.jackson.core.JsonProcessingException;
33

34
import com.fasterxml.jackson.core.type.TypeReference;
35

36
import jakarta.ws.rs.core.GenericType;
37
import jakarta.ws.rs.core.Response;
38
import java.io.IOException;
39
import java.util.logging.Level;
40
import java.util.logging.Logger;
41
import java.util.ArrayList;
42
import java.util.Collections;
43
import java.util.HashSet;
44

45
import com.fasterxml.jackson.core.JsonGenerator;
46
import com.fasterxml.jackson.core.JsonParser;
47
import com.fasterxml.jackson.core.JsonProcessingException;
48
import com.fasterxml.jackson.core.JsonToken;
49
import com.fasterxml.jackson.core.type.TypeReference;
50
import com.fasterxml.jackson.databind.DeserializationContext;
51
import com.fasterxml.jackson.databind.JsonMappingException;
52
import com.fasterxml.jackson.databind.JsonNode;
53
import com.fasterxml.jackson.databind.MapperFeature;
54
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.databind.SerializerProvider;
56
import com.fasterxml.jackson.databind.DeserializationFeature;
57
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
58
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
59
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
60
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
61

62

63
@JsonDeserialize(using = DonationPaymentMethod.DonationPaymentMethodDeserializer.class)
64
@JsonSerialize(using = DonationPaymentMethod.DonationPaymentMethodSerializer.class)
65
public class DonationPaymentMethod extends AbstractOpenApiSchema {
66
    private static final Logger log = Logger.getLogger(DonationPaymentMethod.class.getName());
1✔
67

68
    public static class DonationPaymentMethodSerializer extends StdSerializer<DonationPaymentMethod> {
69
        public DonationPaymentMethodSerializer(Class<DonationPaymentMethod> t) {
70
            super(t);
1✔
71
        }
1✔
72

73
        public DonationPaymentMethodSerializer() {
74
            this(null);
1✔
75
        }
1✔
76

77
        @Override
78
        public void serialize(DonationPaymentMethod value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
79
            jgen.writeObject(value.getActualInstance());
1✔
80
        }
1✔
81
    }
82

83
    public static class DonationPaymentMethodDeserializer extends StdDeserializer<DonationPaymentMethod> {
84
        public DonationPaymentMethodDeserializer() {
85
            this(DonationPaymentMethod.class);
×
86
        }
×
87

88
        public DonationPaymentMethodDeserializer(Class<?> vc) {
89
            super(vc);
×
90
        }
×
91

92
        @Override
93
        public DonationPaymentMethod deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
94
            JsonNode tree = jp.readValueAsTree();
×
95
            Object deserialized = null;
×
96
            boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS);
×
97
            int match = 0;
×
98
            JsonToken token = tree.traverse(jp.getCodec()).nextToken();
×
99

100
            // deserialize ApplePayDetails
101
            try {
102
                boolean attemptParsing = true;
×
103
                // ensure that we respect type coercion as set on the client ObjectMapper
104
                if (ApplePayDetails.class.equals(Integer.class) || ApplePayDetails.class.equals(Long.class) || ApplePayDetails.class.equals(Float.class) || ApplePayDetails.class.equals(Double.class) || ApplePayDetails.class.equals(Boolean.class) || ApplePayDetails.class.equals(String.class)) {
×
105
                    attemptParsing = typeCoercion;
×
106
                    if (!attemptParsing) {
×
107
                        attemptParsing |= ((ApplePayDetails.class.equals(Integer.class) || ApplePayDetails.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT);
×
108
                        attemptParsing |= ((ApplePayDetails.class.equals(Float.class) || ApplePayDetails.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT);
×
109
                        attemptParsing |= (ApplePayDetails.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
×
110
                        attemptParsing |= (ApplePayDetails.class.equals(String.class) && token == JsonToken.VALUE_STRING);
×
111
                    }
112
                }
113
                // Checks if the unique type of the oneOf json matches any of the object TypeEnum values
114
                boolean typeMatch = Arrays.stream(ApplePayDetails.TypeEnum.values()).anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText()));
×
115
                if (attemptParsing || typeMatch) {
×
116
                    // Strict deserialization for oneOf models
117
                    deserialized = JSON.getMapper().readValue(tree.toString(), ApplePayDetails.class);
×
118
                    // typeMatch should enforce proper deserialization
119
                    match++;
×
120
                    log.log(Level.FINER, "Input data matches schema 'ApplePayDetails'");
×
121
                }
122
            } catch (Exception e) {
×
123
                // deserialization failed, continue
124
                log.log(Level.FINER, "Input data does not match schema 'ApplePayDetails'", e);
×
125
            }
×
126

127

128
            // deserialize CardDetails
129
            try {
130
                boolean attemptParsing = true;
×
131
                // ensure that we respect type coercion as set on the client ObjectMapper
132
                if (CardDetails.class.equals(Integer.class) || CardDetails.class.equals(Long.class) || CardDetails.class.equals(Float.class) || CardDetails.class.equals(Double.class) || CardDetails.class.equals(Boolean.class) || CardDetails.class.equals(String.class)) {
×
133
                    attemptParsing = typeCoercion;
×
134
                    if (!attemptParsing) {
×
135
                        attemptParsing |= ((CardDetails.class.equals(Integer.class) || CardDetails.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT);
×
136
                        attemptParsing |= ((CardDetails.class.equals(Float.class) || CardDetails.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT);
×
137
                        attemptParsing |= (CardDetails.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
×
138
                        attemptParsing |= (CardDetails.class.equals(String.class) && token == JsonToken.VALUE_STRING);
×
139
                    }
140
                }
141
                // Checks if the unique type of the oneOf json matches any of the object TypeEnum values
142
                boolean typeMatch = Arrays.stream(CardDetails.TypeEnum.values()).anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText()));
×
143
                if (attemptParsing || typeMatch) {
×
144
                    // Strict deserialization for oneOf models
145
                    deserialized = JSON.getMapper().readValue(tree.toString(), CardDetails.class);
×
146
                    // typeMatch should enforce proper deserialization
147
                    match++;
×
148
                    log.log(Level.FINER, "Input data matches schema 'CardDetails'");
×
149
                }
150
            } catch (Exception e) {
×
151
                // deserialization failed, continue
152
                log.log(Level.FINER, "Input data does not match schema 'CardDetails'", e);
×
153
            }
×
154

155

156
            // deserialize GooglePayDetails
157
            try {
158
                boolean attemptParsing = true;
×
159
                // ensure that we respect type coercion as set on the client ObjectMapper
160
                if (GooglePayDetails.class.equals(Integer.class) || GooglePayDetails.class.equals(Long.class) || GooglePayDetails.class.equals(Float.class) || GooglePayDetails.class.equals(Double.class) || GooglePayDetails.class.equals(Boolean.class) || GooglePayDetails.class.equals(String.class)) {
×
161
                    attemptParsing = typeCoercion;
×
162
                    if (!attemptParsing) {
×
163
                        attemptParsing |= ((GooglePayDetails.class.equals(Integer.class) || GooglePayDetails.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT);
×
164
                        attemptParsing |= ((GooglePayDetails.class.equals(Float.class) || GooglePayDetails.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT);
×
165
                        attemptParsing |= (GooglePayDetails.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
×
166
                        attemptParsing |= (GooglePayDetails.class.equals(String.class) && token == JsonToken.VALUE_STRING);
×
167
                    }
168
                }
169
                // Checks if the unique type of the oneOf json matches any of the object TypeEnum values
170
                boolean typeMatch = Arrays.stream(GooglePayDetails.TypeEnum.values()).anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText()));
×
171
                if (attemptParsing || typeMatch) {
×
172
                    // Strict deserialization for oneOf models
173
                    deserialized = JSON.getMapper().readValue(tree.toString(), GooglePayDetails.class);
×
174
                    // typeMatch should enforce proper deserialization
175
                    match++;
×
176
                    log.log(Level.FINER, "Input data matches schema 'GooglePayDetails'");
×
177
                }
178
            } catch (Exception e) {
×
179
                // deserialization failed, continue
180
                log.log(Level.FINER, "Input data does not match schema 'GooglePayDetails'", e);
×
181
            }
×
182

183

184
            // deserialize IdealDetails
185
            try {
186
                boolean attemptParsing = true;
×
187
                // ensure that we respect type coercion as set on the client ObjectMapper
188
                if (IdealDetails.class.equals(Integer.class) || IdealDetails.class.equals(Long.class) || IdealDetails.class.equals(Float.class) || IdealDetails.class.equals(Double.class) || IdealDetails.class.equals(Boolean.class) || IdealDetails.class.equals(String.class)) {
×
189
                    attemptParsing = typeCoercion;
×
190
                    if (!attemptParsing) {
×
191
                        attemptParsing |= ((IdealDetails.class.equals(Integer.class) || IdealDetails.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT);
×
192
                        attemptParsing |= ((IdealDetails.class.equals(Float.class) || IdealDetails.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT);
×
193
                        attemptParsing |= (IdealDetails.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
×
194
                        attemptParsing |= (IdealDetails.class.equals(String.class) && token == JsonToken.VALUE_STRING);
×
195
                    }
196
                }
197
                // Checks if the unique type of the oneOf json matches any of the object TypeEnum values
198
                boolean typeMatch = Arrays.stream(IdealDetails.TypeEnum.values()).anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText()));
×
199
                if (attemptParsing || typeMatch) {
×
200
                    // Strict deserialization for oneOf models
201
                    deserialized = JSON.getMapper().readValue(tree.toString(), IdealDetails.class);
×
202
                    // typeMatch should enforce proper deserialization
203
                    match++;
×
204
                    log.log(Level.FINER, "Input data matches schema 'IdealDetails'");
×
205
                }
206
            } catch (Exception e) {
×
207
                // deserialization failed, continue
208
                log.log(Level.FINER, "Input data does not match schema 'IdealDetails'", e);
×
209
            }
×
210

211

212
            // deserialize PayWithGoogleDetails
213
            try {
214
                boolean attemptParsing = true;
×
215
                // ensure that we respect type coercion as set on the client ObjectMapper
216
                if (PayWithGoogleDetails.class.equals(Integer.class) || PayWithGoogleDetails.class.equals(Long.class) || PayWithGoogleDetails.class.equals(Float.class) || PayWithGoogleDetails.class.equals(Double.class) || PayWithGoogleDetails.class.equals(Boolean.class) || PayWithGoogleDetails.class.equals(String.class)) {
×
217
                    attemptParsing = typeCoercion;
×
218
                    if (!attemptParsing) {
×
219
                        attemptParsing |= ((PayWithGoogleDetails.class.equals(Integer.class) || PayWithGoogleDetails.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT);
×
220
                        attemptParsing |= ((PayWithGoogleDetails.class.equals(Float.class) || PayWithGoogleDetails.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT);
×
221
                        attemptParsing |= (PayWithGoogleDetails.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
×
222
                        attemptParsing |= (PayWithGoogleDetails.class.equals(String.class) && token == JsonToken.VALUE_STRING);
×
223
                    }
224
                }
225
                // Checks if the unique type of the oneOf json matches any of the object TypeEnum values
226
                boolean typeMatch = Arrays.stream(PayWithGoogleDetails.TypeEnum.values()).anyMatch((t) -> t.getValue().contains(tree.findValue("type").asText()));
×
227
                if (attemptParsing || typeMatch) {
×
228
                    // Strict deserialization for oneOf models
229
                    deserialized = JSON.getMapper().readValue(tree.toString(), PayWithGoogleDetails.class);
×
230
                    // typeMatch should enforce proper deserialization
231
                    match++;
×
232
                    log.log(Level.FINER, "Input data matches schema 'PayWithGoogleDetails'");
×
233
                }
234
            } catch (Exception e) {
×
235
                // deserialization failed, continue
236
                log.log(Level.FINER, "Input data does not match schema 'PayWithGoogleDetails'", e);
×
237
            }
×
238

239
            // Throw error if there is no match
240
            if (match == 0) {
×
241
                throw new IOException(String.format("Failed deserialization for DonationPaymentMethod: %d classes match result, expected 1", match));
×
242
            }
243
            // Log warning if there is more than one match
244
            if (match > 1) {
×
245
                log.log(Level.WARNING, String.format("Warning, indecisive deserialization for DonationPaymentMethod: %d classes match result, expected 1", match));
×
246
            }
247

248
            DonationPaymentMethod ret = new DonationPaymentMethod();
×
249
            ret.setActualInstance(deserialized);
×
250
            return ret;
×
251
        }
252

253
        /**
254
         * Handle deserialization of the 'null' value.
255
         */
256
        @Override
257
        public DonationPaymentMethod getNullValue(DeserializationContext ctxt) throws JsonMappingException {
258
            throw new JsonMappingException(ctxt.getParser(), "DonationPaymentMethod cannot be null");
×
259
        }
260
    }
261

262
    // store a list of schema names defined in oneOf
263
    public static final Map<String, GenericType> schemas = new HashMap<String, GenericType>();
1✔
264

265
    public DonationPaymentMethod() {
266
        super("oneOf", Boolean.FALSE);
×
267
    }
×
268

269
    public DonationPaymentMethod(ApplePayDetails o) {
270
        super("oneOf", Boolean.FALSE);
×
271
        setActualInstance(o);
×
272
    }
×
273

274
    public DonationPaymentMethod(CardDetails o) {
275
        super("oneOf", Boolean.FALSE);
1✔
276
        setActualInstance(o);
1✔
277
    }
1✔
278

279
    public DonationPaymentMethod(GooglePayDetails o) {
280
        super("oneOf", Boolean.FALSE);
×
281
        setActualInstance(o);
×
282
    }
×
283

284
    public DonationPaymentMethod(IdealDetails o) {
285
        super("oneOf", Boolean.FALSE);
×
286
        setActualInstance(o);
×
287
    }
×
288

289
    public DonationPaymentMethod(PayWithGoogleDetails o) {
290
        super("oneOf", Boolean.FALSE);
×
291
        setActualInstance(o);
×
292
    }
×
293

294
    static {
295
        schemas.put("ApplePayDetails", new GenericType<ApplePayDetails>() {
1✔
296
        });
297
        schemas.put("CardDetails", new GenericType<CardDetails>() {
1✔
298
        });
299
        schemas.put("GooglePayDetails", new GenericType<GooglePayDetails>() {
1✔
300
        });
301
        schemas.put("IdealDetails", new GenericType<IdealDetails>() {
1✔
302
        });
303
        schemas.put("PayWithGoogleDetails", new GenericType<PayWithGoogleDetails>() {
1✔
304
        });
305
        JSON.registerDescendants(DonationPaymentMethod.class, Collections.unmodifiableMap(schemas));
1✔
306
    }
1✔
307

308
    @Override
309
    public Map<String, GenericType> getSchemas() {
310
        return DonationPaymentMethod.schemas;
×
311
    }
312

313
    /**
314
     * Set the instance that matches the oneOf child schema, check
315
     * the instance parameter is valid against the oneOf child schemas:
316
     * ApplePayDetails, CardDetails, GooglePayDetails, IdealDetails, PayWithGoogleDetails
317
     *
318
     * It could be an instance of the 'oneOf' schemas.
319
     * The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
320
     */
321
    @Override
322
    public void setActualInstance(Object instance) {
323
        if (JSON.isInstanceOf(ApplePayDetails.class, instance, new HashSet<Class<?>>())) {
1✔
324
            super.setActualInstance(instance);
×
325
            return;
×
326
        }
327

328
        if (JSON.isInstanceOf(CardDetails.class, instance, new HashSet<Class<?>>())) {
1✔
329
            super.setActualInstance(instance);
1✔
330
            return;
1✔
331
        }
332

333
        if (JSON.isInstanceOf(GooglePayDetails.class, instance, new HashSet<Class<?>>())) {
×
334
            super.setActualInstance(instance);
×
335
            return;
×
336
        }
337

338
        if (JSON.isInstanceOf(IdealDetails.class, instance, new HashSet<Class<?>>())) {
×
339
            super.setActualInstance(instance);
×
340
            return;
×
341
        }
342

343
        if (JSON.isInstanceOf(PayWithGoogleDetails.class, instance, new HashSet<Class<?>>())) {
×
344
            super.setActualInstance(instance);
×
345
            return;
×
346
        }
347

348
        throw new RuntimeException("Invalid instance type. Must be ApplePayDetails, CardDetails, GooglePayDetails, IdealDetails, PayWithGoogleDetails");
×
349
    }
350

351
    /**
352
     * Get the actual instance, which can be the following:
353
     * ApplePayDetails, CardDetails, GooglePayDetails, IdealDetails, PayWithGoogleDetails
354
     *
355
     * @return The actual instance (ApplePayDetails, CardDetails, GooglePayDetails, IdealDetails, PayWithGoogleDetails)
356
     */
357
    @Override
358
    public Object getActualInstance() {
359
        return super.getActualInstance();
1✔
360
    }
361

362
    /**
363
     * Get the actual instance of `ApplePayDetails`. If the actual instance is not `ApplePayDetails`,
364
     * the ClassCastException will be thrown.
365
     *
366
     * @return The actual instance of `ApplePayDetails`
367
     * @throws ClassCastException if the instance is not `ApplePayDetails`
368
     */
369
    public ApplePayDetails getApplePayDetails() throws ClassCastException {
370
        return (ApplePayDetails)super.getActualInstance();
×
371
    }
372

373
    /**
374
     * Get the actual instance of `CardDetails`. If the actual instance is not `CardDetails`,
375
     * the ClassCastException will be thrown.
376
     *
377
     * @return The actual instance of `CardDetails`
378
     * @throws ClassCastException if the instance is not `CardDetails`
379
     */
380
    public CardDetails getCardDetails() throws ClassCastException {
381
        return (CardDetails)super.getActualInstance();
×
382
    }
383

384
    /**
385
     * Get the actual instance of `GooglePayDetails`. If the actual instance is not `GooglePayDetails`,
386
     * the ClassCastException will be thrown.
387
     *
388
     * @return The actual instance of `GooglePayDetails`
389
     * @throws ClassCastException if the instance is not `GooglePayDetails`
390
     */
391
    public GooglePayDetails getGooglePayDetails() throws ClassCastException {
392
        return (GooglePayDetails)super.getActualInstance();
×
393
    }
394

395
    /**
396
     * Get the actual instance of `IdealDetails`. If the actual instance is not `IdealDetails`,
397
     * the ClassCastException will be thrown.
398
     *
399
     * @return The actual instance of `IdealDetails`
400
     * @throws ClassCastException if the instance is not `IdealDetails`
401
     */
402
    public IdealDetails getIdealDetails() throws ClassCastException {
403
        return (IdealDetails)super.getActualInstance();
×
404
    }
405

406
    /**
407
     * Get the actual instance of `PayWithGoogleDetails`. If the actual instance is not `PayWithGoogleDetails`,
408
     * the ClassCastException will be thrown.
409
     *
410
     * @return The actual instance of `PayWithGoogleDetails`
411
     * @throws ClassCastException if the instance is not `PayWithGoogleDetails`
412
     */
413
    public PayWithGoogleDetails getPayWithGoogleDetails() throws ClassCastException {
414
        return (PayWithGoogleDetails)super.getActualInstance();
×
415
    }
416

417
    /**
418
    * Create an instance of DonationPaymentMethod given an JSON string
419
    *
420
    * @param jsonString JSON string
421
    * @return An instance of DonationPaymentMethod
422
    * @throws IOException if the JSON string is invalid with respect to DonationPaymentMethod
423
    */
424
    public static DonationPaymentMethod fromJson(String jsonString) throws IOException {
425
        return JSON.getMapper().readValue(jsonString, DonationPaymentMethod.class);
×
426
    }
427

428
    /**
429
    * Convert an instance of DonationPaymentMethod to an JSON string
430
    *
431
    * @return JSON string
432
    */
433
    public String toJson() throws JsonProcessingException {
434
        return JSON.getMapper().writeValueAsString(this);
×
435
    }
436
}
437

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc