Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public static Type resolveTypeArguments(ParameterizedType typeToResolve, Type ty
}
}

if (resolvedArgs[i] == null) {
if (resolvedArgs[i] == null || resolvedArgs[i].equals(typeToResolve)) {
if (typeToSearch instanceof Class) {
return Object.class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@

package org.eclipse.yasson.defaultmapping.generics;

import static org.eclipse.yasson.Jsonbs.defaultJsonb;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
Expand All @@ -30,8 +36,6 @@
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import java.lang.reflect.Field;
import java.util.Collection;
import org.eclipse.yasson.TestTypeToken;
import org.eclipse.yasson.adapters.model.GenericBox;
import org.eclipse.yasson.defaultmapping.generics.model.AnotherGenericTestClass;
Expand All @@ -48,24 +52,21 @@
import org.eclipse.yasson.defaultmapping.generics.model.GenericArrayClass;
import org.eclipse.yasson.defaultmapping.generics.model.GenericTestClass;
import org.eclipse.yasson.defaultmapping.generics.model.GenericWithUnboundedWildcardClass;
import org.eclipse.yasson.defaultmapping.generics.model.LowerBoundTypeVariableWithCollectionAttributeClass;
import org.eclipse.yasson.defaultmapping.generics.model.MultiLevelExtendedGenericTestClass;
import org.eclipse.yasson.defaultmapping.generics.model.MultipleBoundsContainer;
import org.eclipse.yasson.defaultmapping.generics.model.MyCyclicGenericClass;
import org.eclipse.yasson.defaultmapping.generics.model.PropagatedGenericClass;
import org.eclipse.yasson.defaultmapping.generics.model.Shape;
import org.eclipse.yasson.defaultmapping.generics.model.StaticCreatorContainer;
import org.eclipse.yasson.defaultmapping.generics.model.TreeContainer;
import org.eclipse.yasson.defaultmapping.generics.model.TreeElement;
import org.eclipse.yasson.defaultmapping.generics.model.WildCardClass;
import org.eclipse.yasson.defaultmapping.generics.model.WildcardMultipleBoundsClass;
import org.eclipse.yasson.serializers.model.Box;
import org.eclipse.yasson.serializers.model.Crate;
import org.junit.jupiter.api.Test;

import static org.eclipse.yasson.Jsonbs.defaultJsonb;
import org.eclipse.yasson.defaultmapping.generics.model.LowerBoundTypeVariableWithCollectionAttributeClass;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* This class contains JSONB default mapping generics tests.
*
Expand Down Expand Up @@ -513,6 +514,18 @@ public void wildcardCollectionContainer() {
final CollectionContainer result = defaultJsonb.fromJson(expectedJson, CollectionContainer.class);
assertEquals(collectionContainer, result);
}

@Test
public void genericUpperBoundContainer() {
final String expectedJson = "{\"tree\":{\"children\":[{\"children\":[],\"name\":\"child\"}],\"name\":\"parent\"}}";
final TreeContainer<TreeElement> container = new TreeContainer<>();
final TreeElement parent = new TreeElement("parent");
parent.setChildren(List.of(new TreeElement("child")));
container.setTree(parent);

assertEquals(expectedJson, defaultJsonb.toJson(container));

}

public interface FunctionalInterface<T> {
T getValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025 Red Hat, Inc. and/or its affiliates.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.eclipse.yasson.defaultmapping.generics.model;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
public class TreeContainer<T extends TreeTypeContainer<T>> {

private TreeTypeContainer<T> tree;

public TreeTypeContainer<T> getTree() {
return tree;
}

public void setTree(final TreeTypeContainer<T> tree) {
this.tree = tree;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2025 Red Hat, Inc. and/or its affiliates.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.eclipse.yasson.defaultmapping.generics.model;

import java.util.ArrayList;
import java.util.List;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
public class TreeElement implements TreeTypeContainer<TreeElement> {

private final String name;
private List<TreeElement> children = new ArrayList<>();

public TreeElement(final String name) {
this.name = name;
}

public String getName() {
return name;
}

public List<TreeElement> getChildren() {
return children;
}

public void setChildren(final List<TreeElement> children) {
this.children = children;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2025 Red Hat, Inc. and/or its affiliates.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.eclipse.yasson.defaultmapping.generics.model;

import java.util.List;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
public interface TreeTypeContainer<T extends TreeTypeContainer<T>> {

List<T> getChildren();

void setChildren(List<T> children);
}