|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2015, 2023 Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials are made available under the
|
5 | 5 | * terms of the Eclipse Public License v. 2.0 which is available at
|
|
13 | 13 | package org.eclipse.yasson.defaultmapping.generics;
|
14 | 14 |
|
15 | 15 | import java.lang.reflect.Type;
|
| 16 | +import java.lang.reflect.WildcardType; |
16 | 17 | import java.math.BigDecimal;
|
17 | 18 | import java.text.ParseException;
|
18 | 19 | import java.text.SimpleDateFormat;
|
|
36 | 37 | import org.eclipse.yasson.defaultmapping.generics.model.AnotherGenericTestClass;
|
37 | 38 | import org.eclipse.yasson.defaultmapping.generics.model.BoundedGenericClass;
|
38 | 39 | import org.eclipse.yasson.defaultmapping.generics.model.Circle;
|
| 40 | +import org.eclipse.yasson.defaultmapping.generics.model.CollectionContainer; |
| 41 | +import org.eclipse.yasson.defaultmapping.generics.model.CollectionElement; |
39 | 42 | import org.eclipse.yasson.defaultmapping.generics.model.CollectionWrapper;
|
40 | 43 | import org.eclipse.yasson.defaultmapping.generics.model.ColoredCircle;
|
| 44 | +import org.eclipse.yasson.defaultmapping.generics.model.ConstructorContainer; |
41 | 45 | import org.eclipse.yasson.defaultmapping.generics.model.CyclicSubClass;
|
42 | 46 | import org.eclipse.yasson.defaultmapping.generics.model.FinalGenericWrapper;
|
43 | 47 | import org.eclipse.yasson.defaultmapping.generics.model.FinalMember;
|
|
49 | 53 | import org.eclipse.yasson.defaultmapping.generics.model.MyCyclicGenericClass;
|
50 | 54 | import org.eclipse.yasson.defaultmapping.generics.model.PropagatedGenericClass;
|
51 | 55 | import org.eclipse.yasson.defaultmapping.generics.model.Shape;
|
| 56 | +import org.eclipse.yasson.defaultmapping.generics.model.StaticCreatorContainer; |
52 | 57 | import org.eclipse.yasson.defaultmapping.generics.model.WildCardClass;
|
53 | 58 | import org.eclipse.yasson.defaultmapping.generics.model.WildcardMultipleBoundsClass;
|
54 | 59 | import org.eclipse.yasson.serializers.model.Box;
|
@@ -474,6 +479,40 @@ public void lowerBoundTypeVariableInCollectionAttribute() throws Exception {
|
474 | 479 | assertEquals(6, fromJson.get(0).field1);
|
475 | 480 |
|
476 | 481 | }
|
| 482 | + |
| 483 | + @Test |
| 484 | + public void genericConstructorCreator() { |
| 485 | + final String expectedJson = "{\"value\":\"Test\"}"; |
| 486 | + final ConstructorContainer<String> container = new ConstructorContainer<>("Test"); |
| 487 | + |
| 488 | + assertEquals(expectedJson, defaultJsonb.toJson(container)); |
| 489 | + assertEquals(container, defaultJsonb.fromJson(expectedJson, ConstructorContainer.class)); |
| 490 | + } |
| 491 | + |
| 492 | + @Test |
| 493 | + public void genericStaticCreator() { |
| 494 | + final String expectedJson = "{\"value\":\"static\"}"; |
| 495 | + final StaticCreatorContainer<String> container = StaticCreatorContainer.create("static"); |
| 496 | + |
| 497 | + assertEquals(expectedJson, defaultJsonb.toJson(container)); |
| 498 | + assertEquals(container, defaultJsonb.fromJson(expectedJson, StaticCreatorContainer.class)); |
| 499 | + } |
| 500 | + |
| 501 | + @Test |
| 502 | + public void wildcardCollectionContainer() { |
| 503 | + final String expectedJson = "{\"collection\":{\"collection\":[{\"wrapped\":\"wrappedElement\"}]}}"; |
| 504 | + final CollectionContainer collectionContainer = new CollectionContainer(); |
| 505 | + final CollectionWrapper<CollectionElement<?>> collectionWrapper = new CollectionWrapper<>(); |
| 506 | + final CollectionElement<String> wildcardType = new CollectionElement<>(); |
| 507 | + wildcardType.setWrapped("wrappedElement"); |
| 508 | + final Collection<CollectionElement<?>> list = List.of(wildcardType); |
| 509 | + collectionWrapper.setCollection(list); |
| 510 | + collectionContainer.setCollection(collectionWrapper); |
| 511 | + |
| 512 | + assertEquals(expectedJson, defaultJsonb.toJson(collectionContainer)); |
| 513 | + final CollectionContainer result = defaultJsonb.fromJson(expectedJson, CollectionContainer.class); |
| 514 | + assertEquals(collectionContainer, result); |
| 515 | + } |
477 | 516 |
|
478 | 517 | public interface FunctionalInterface<T> {
|
479 | 518 | T getValue();
|
|
0 commit comments