Skip to content

Commit 2d9d784

Browse files
committed
covariant types
1 parent e31e739 commit 2d9d784

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
- deserialization support for wildcard types
910
- deserialization support for java.lang.Iterable
1011
- raised the minimum JVM source and target version to 8
1112
- All-Arguments constructor deserialization

src/main/java/com/arangodb/velocypack/VPack.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,13 @@ private <T> Object getValue(
638638
} else if (realType instanceof WildcardType) {
639639
final WildcardType wType = (WildcardType) realType;
640640
final Type rawType = wType.getUpperBounds()[0];
641-
value = deserializeObject(parent, vpack, rawType, fieldName, referencingElement);
641+
value = getValue(
642+
parent,
643+
vpack,
644+
rawType,
645+
fieldName,
646+
referencingElement
647+
);
642648
} else if (realType instanceof GenericArrayType) {
643649
throw new VPackParserException(new IllegalArgumentException("Generic arrays are not supported!"));
644650
} else if (Iterable.class.isAssignableFrom((Class<?>) realType)) {
@@ -910,6 +916,10 @@ private void addValue(
910916
} else {
911917
serializeObject(name, value, builder, additionalFields);
912918
}
919+
} else if (type instanceof WildcardType) {
920+
final WildcardType wType = (WildcardType) type;
921+
final Type rawType = wType.getUpperBounds()[0];
922+
addValue(name, rawType, value, builder, fieldInfo, additionalFields);
913923
} else if (type instanceof Class && Iterable.class.isAssignableFrom((Class<?>) type)) {
914924
serializeIterable(name, value, builder, null);
915925
} else if (type instanceof Class && Map.class.isAssignableFrom((Class<?>) type)) {

src/test/java/com/arangodb/velocypack/immutable/ImmutablesTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.Test;
2626

2727
import java.util.Arrays;
28+
import java.util.Collections;
2829

2930
import static org.hamcrest.MatcherAssert.assertThat;
3031
import static org.hamcrest.Matchers.is;
@@ -44,6 +45,10 @@ public void serdePerson() {
4445
.withName("name")
4546
.withAge(99)
4647
.withSecondNames(Arrays.asList("aaa", "bbb", "ccc"))
48+
.withAddresses(Arrays.asList(
49+
Collections.singletonMap("home", "Avocado Street 14"),
50+
Collections.singletonMap("work", "Java Street 14")
51+
))
4752
.buildIt();
4853
System.out.println(original);
4954
VPackSlice serialized = vpack.serialize(original);

src/test/java/com/arangodb/velocypack/immutable/Person.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.arangodb.velocypack.annotations.VPackPOJOBuilder;
2424
import org.immutables.value.Value;
2525

26+
import java.util.List;
27+
import java.util.Map;
2628
import java.util.Set;
2729

2830
/**
@@ -45,4 +47,6 @@ public static ImmutablePerson.Builder builderFunction() {
4547

4648
abstract Set<String> getSecondNames();
4749

50+
abstract List<Map<String, String>> getAddresses();
51+
4852
}

0 commit comments

Comments
 (0)