-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#380] It's not possible to define multiple @ProtoAdapters for a sing…
…le Interface type
- Loading branch information
1 parent
2cc5f09
commit e2ed575
Showing
11 changed files
with
136 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
types/src/test/java/org/infinispan/protostream/types/java/EmptyListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.infinispan.protostream.types.java; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.infinispan.protostream.annotations.ProtoAdapter; | ||
import org.infinispan.protostream.annotations.ProtoFactory; | ||
|
||
@ProtoAdapter( | ||
value = List.class, | ||
subClassNames = "java.util.Collections$EmptyList" | ||
) | ||
public class EmptyListAdapter { | ||
@ProtoFactory | ||
List<?> create() { | ||
return Collections.emptyList(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
types/src/test/java/org/infinispan/protostream/types/java/ListOfAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.infinispan.protostream.types.java; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.infinispan.protostream.WrappedMessage; | ||
import org.infinispan.protostream.annotations.ProtoAdapter; | ||
import org.infinispan.protostream.annotations.ProtoFactory; | ||
import org.infinispan.protostream.annotations.ProtoField; | ||
|
||
@ProtoAdapter( | ||
value = List.class, | ||
subClassNames = { | ||
"java.util.ImmutableCollections$ListN", | ||
"java.util.ImmutableCollections$List12" | ||
} | ||
) | ||
public class ListOfAdapter { | ||
@ProtoFactory | ||
List<?> create(WrappedMessage[] elements) { | ||
return elements == null ? null : | ||
List.of(Arrays.stream(elements).map(WrappedMessage::getValue).toArray()); | ||
} | ||
|
||
@ProtoField(1) | ||
WrappedMessage[] elements(List<?> list) { | ||
return list == null ? null : list.stream().map(WrappedMessage::new).toArray(WrappedMessage[]::new); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
types/src/test/java/org/infinispan/protostream/types/java/ListSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.infinispan.protostream.types.java; | ||
|
||
import org.infinispan.protostream.GeneratedSchema; | ||
import org.infinispan.protostream.annotations.ProtoSchema; | ||
|
||
@ProtoSchema( | ||
includeClasses = { | ||
ListOfAdapter.class, | ||
EmptyListAdapter.class, | ||
SingletonListAdapter.class | ||
}, | ||
schemaFileName = "list.proto", | ||
schemaFilePath = "proto/", | ||
schemaPackageName = "collections") | ||
public interface ListSchema extends GeneratedSchema { | ||
} |
27 changes: 27 additions & 0 deletions
27
types/src/test/java/org/infinispan/protostream/types/java/SingletonListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.infinispan.protostream.types.java; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.infinispan.protostream.WrappedMessage; | ||
import org.infinispan.protostream.annotations.ProtoAdapter; | ||
import org.infinispan.protostream.annotations.ProtoFactory; | ||
import org.infinispan.protostream.annotations.ProtoField; | ||
|
||
@ProtoAdapter( | ||
value = List.class, | ||
subClassNames = "java.util.Collections$SingletonList" | ||
) | ||
public class SingletonListAdapter { | ||
|
||
@ProtoFactory | ||
List<?> create(WrappedMessage element) { | ||
return Collections.singletonList(element == null ? null : element.getValue()); | ||
} | ||
|
||
@ProtoField(1) | ||
WrappedMessage getElement(List<?> list) { | ||
var val = list.get(0); | ||
return val == null ? null : new WrappedMessage(val); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters