Skip to content

Commit

Permalink
[eclipse-ee4j#620]Small Javadoc, type, import corrections. Rewrite on…
Browse files Browse the repository at this point in the history
…e of CollectionsTest's test with stream.

Signed-off-by: Anton Pinsky <[email protected]>
  • Loading branch information
api-from-the-ion committed Nov 1, 2023
1 parent 84f05f1 commit f660a9f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Type searchParametrizedType(Type typeToSearch, TypeVariable<?> typeVar) {
return matchedGenericType;
}
parameterizedSubclasses.push(parameterizedType);
return searchParametrizedType(((Class) parameterizedType.getRawType()).getGenericSuperclass(), typeVar);
return searchParametrizedType(((Class<?>) parameterizedType.getRawType()).getGenericSuperclass(), typeVar);
}

private Type checkSubclassRuntimeInfo(TypeVariable<?> typeVar) {
Expand Down Expand Up @@ -120,6 +120,6 @@ private static ParameterizedType findParameterizedSuperclass(Type type) {
if (!(type instanceof Class)) {
throw new JsonbException(Messages.getMessage(MessageKeys.RESOLVE_PARAMETRIZED_TYPE, type));
}
return findParameterizedSuperclass(((Class) type).getGenericSuperclass());
return findParameterizedSuperclass(((Class<?>) type).getGenericSuperclass());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AdapterBinding(Type fromType, Type toType, JsonbAdapter<Original, Adapted

/**
* Represents a type to which to adapt into.
*
* <p>
* During marshalling object property is adapted to this type and result is marshalled.
* During unmarshalling object is unmarshalled into this type first, than converted to field type and set.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* CDI instance manager.
* Instances are created and stored per instance of {@link JsonBinding}.
* Calling close on JsonBinding, cleans up Jsonb CDI instances and in case of "dependant" scope its dependencies.
*
* <p>
* CDI API dependency is optional, this class is never referenced / loaded if CDI API is not resolvable.
*/
public class BeanManagerInstanceCreator implements JsonbComponentInstanceCreator {
Expand Down Expand Up @@ -71,7 +71,7 @@ public <T> T getOrCreateComponent(Class<T> componentClass) {
final T beanInstance = injectionTarget.produce(creationalContext);
injectionTarget.inject(beanInstance, creationalContext);
injectionTarget.postConstruct(beanInstance);
return new CDIManagedBean<T>(beanInstance, injectionTarget, creationalContext);
return new CDIManagedBean<>(beanInstance, injectionTarget, creationalContext);
}).getInstance();
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public Object getValue(Object object) {

/**
* Sets a property.
*
* <p>
* If not writable (final, transient, static), ignores property.
*
* @param object Object to set value in.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static class AnnotatedPojo<T,X> {
}

@Test
public void testIncompatibleAdapter() throws Exception {
public void testIncompatibleAdapter() {
IncompatibleAdapterPojo<?, ?> incompatibleAdapterFieldPojo = new IncompatibleAdapterPojo<>();
incompatibleAdapterFieldPojo.str = "STR";
try {
Expand All @@ -85,7 +85,7 @@ public void testGenericFieldsMatch() {
}

@Test
public void testAnnotatedTbox() throws Exception {
public void testAnnotatedTbox() {
AnnotatedPojo<?, ?> pojo = new AnnotatedPojo<>();
pojo.box = new Box("STR", 101);
String marshalledJson = defaultJsonb.toJson(pojo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@
import java.util.Deque;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Optional;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.eclipse.yasson.TestTypeToken;
import org.eclipse.yasson.defaultmapping.generics.model.Circle;
Expand Down Expand Up @@ -87,6 +88,7 @@ public void testListOfNumbers() {
numberList.add(10);

String result = nullableJsonb.toJson(numberList, new TestTypeToken<List<Number>>(){}.getType());
assertEquals("[1,2.0,10]", result);
}

@Test
Expand All @@ -108,26 +110,19 @@ public void testListOfListsOfStrings() {

@Test
public void listOfMapsOfListsOfMaps() {
List<Map<String, List<Map<String, Integer>>>> listOfMapsOfListsOfMaps = new ArrayList<>();

for(int i = 0; i < 3; i++) {
Map<String, List<Map<String, Integer>>> mapOfListsOfMap = new HashMap<>();

for(int j = 0; j < 3; j++) {
List<Map<String, Integer>> listOfMaps = new ArrayList<>();

for(int k = 0; k < 3; k++) {
Map<String, Integer> stringIntegerMap = new HashMap<>();
stringIntegerMap.put("first", 1);
stringIntegerMap.put("second", 2);
stringIntegerMap.put("third", 3);
listOfMaps.add(stringIntegerMap);
}
mapOfListsOfMap.put(String.valueOf(j), listOfMaps);
}
listOfMapsOfListsOfMaps.add(mapOfListsOfMap);
}

List<Map<String, List<Map<String, Integer>>>> listOfMapsOfListsOfMaps = IntStream.range(0, 3).mapToObj(i ->
IntStream.range(0, 3).boxed().collect(Collectors.toMap(String::valueOf, j ->
IntStream.range(0, 3).mapToObj(k ->
IntStream.range(1, 4).boxed().collect(Collectors.toMap(l -> switch (l) {
case 1 -> "first";
case 2 -> "second";
case 3 -> "third";
default -> throw new IllegalStateException("Unexpected value: " + l);
}, Function.identity()))
).toList()
))
).toList();

String expected = "[{\"0\":[{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2}],\"1\":[{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2}],\"2\":[{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2}]},{\"0\":[{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2}],\"1\":[{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2}],\"2\":[{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2}]},{\"0\":[{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2}],\"1\":[{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2}],\"2\":[{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2},{\"third\":3,\"first\":1,\"second\":2}]}]";
assertEquals(expected, nullableJsonb.toJson(listOfMapsOfListsOfMaps));
ArrayList<Map<String, List<Map<String, Integer>>>> result = nullableJsonb.fromJson(expected, new TestTypeToken<ArrayList<Map<String, List<Map<String, Integer>>>>>(){}.getType());
Expand Down Expand Up @@ -290,7 +285,7 @@ public static class ConcurrentMapContainer {
public void testConcurrentMaps() {
// ConcurrentMap
ConcurrentMapContainer c = new ConcurrentMapContainer();
c.concurrentMap = new ConcurrentHashMap<String, String>();
c.concurrentMap = new ConcurrentHashMap<>();
c.concurrentMap.put("foo", "fooVal");
c.concurrentMap.put("bar", "barVal");
String expectedJson = "{\"concurrentMap\":{\"bar\":\"barVal\",\"foo\":\"fooVal\"}}";
Expand All @@ -299,7 +294,7 @@ public void testConcurrentMaps() {

// ConcurrentHashMap
c = new ConcurrentMapContainer();
c.concurrentHashMap = new ConcurrentHashMap<String, String>();
c.concurrentHashMap = new ConcurrentHashMap<>();
c.concurrentHashMap.put("foo", "fooVal2");
c.concurrentHashMap.put("bar", "barVal2");
expectedJson = "{\"concurrentHashMap\":{\"bar\":\"barVal2\",\"foo\":\"fooVal2\"}}";
Expand All @@ -308,7 +303,7 @@ public void testConcurrentMaps() {

// ConcurrentNavigableMap
c = new ConcurrentMapContainer();
c.concurrentNavigableMap = new ConcurrentSkipListMap<String, String>();
c.concurrentNavigableMap = new ConcurrentSkipListMap<>();
c.concurrentNavigableMap.put("foo", "fooVal3");
c.concurrentNavigableMap.put("bar", "barVal3");
expectedJson = "{\"concurrentNavigableMap\":{\"bar\":\"barVal3\",\"foo\":\"fooVal3\"}}";
Expand All @@ -317,7 +312,7 @@ public void testConcurrentMaps() {

// ConcurrentSkipListMap
c = new ConcurrentMapContainer();
c.concurrentSkipListMap = new ConcurrentSkipListMap<String, String>();
c.concurrentSkipListMap = new ConcurrentSkipListMap<>();
c.concurrentSkipListMap.put("foo", "fooVal4");
c.concurrentSkipListMap.put("bar", "barVal4");
expectedJson = "{\"concurrentSkipListMap\":{\"bar\":\"barVal4\",\"foo\":\"fooVal4\"}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import org.eclipse.yasson.defaultmapping.specific.model.OptionalWrapper;
import org.eclipse.yasson.defaultmapping.specific.model.NotMatchingGettersAndSetters;
import org.eclipse.yasson.defaultmapping.specific.model.Street;
import org.eclipse.yasson.internal.JsonBindingBuilder;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import java.util.*;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public class MapToObjectSerializerTest {
enum TestEnum {
ONE, TWO;

@Override
/**
* Force to lower case to check toString is not used during serialization of maps
*/
@Override
public String toString() {
return this.name().toLowerCase();
}
Expand Down Expand Up @@ -90,17 +90,17 @@ public String toString() {
}
}

public static class MapObjectIntegerString extends MapObject<Integer, String> {};
public static class MapObjectIntegerString extends MapObject<Integer, String> {}

public static class MapObjectBigIntegerString extends MapObject<BigInteger, String> {};
public static class MapObjectBigIntegerString extends MapObject<BigInteger, String> {}

public static class MapObjectEnumString extends MapObject<TestEnum, String> {};
public static class MapObjectEnumString extends MapObject<TestEnum, String> {}

public static class MapObjectStringString extends MapObject<String, String> {};
public static class MapObjectStringString extends MapObject<String, String> {}

public static class MapObjectBooleanString extends MapObject<Boolean, String> {};
public static class MapObjectBooleanString extends MapObject<Boolean, String> {}

/**
/**
* Test serialization of Map with Number keys and String values.
*/
@Test
Expand Down

0 comments on commit f660a9f

Please sign in to comment.