Hi
With the following cache definition e.g: Cache<String, ArrayList<Sensor>>
, with Protobuf, the values are not being marshalled.
To recreated this issue, you can create a new project:
mvn archetype:generate -DarchetypeGroupId=org.infinispan.archetypes -DarchetypeArtifactId=embedded -DarchetypeVersion=14.0.1.Final
added the latest lib in the pom.xml:
...
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<version>14.0.0.CR2</version>
</dependency>
...
Edited the upd xml file:
<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:schemaLocation="urn:infinispan:config:14.0 http://infinispan.org/schemas/infinispan-config-14.0.xsd"
xmlns="urn:infinispan:config:14.0">
<cache-container default-cache="default" statistics="true">
<serialization marshaller="org.infinispan.commons.marshall.ProtoStreamMarshaller">
<context-initializer class="test.com.LibraryInitializerImpl"/>
<allow-list>
<class>test.com.Sensor</class>
</allow-list>
</serialization>
<transport stack="udp" cluster="mycluster" />
<distributed-cache name="stockTickers" mode="SYNC">
<encoding>
<key media-type="application/x-protostream"/>
<value media-type="application/x-protostream"/>
</encoding>
<locking isolation="REPEATABLE_READ" striping="false"/>
</distributed-cache>
<replicated-cache name="default"/>
</cache-container>
</infinispan>
A very simple POJO
public class Sensor {
@ProtoField(value = 1, defaultValue = "0")
public int anInt;
public Sensor() {
}
public Sensor(int anInt) {
this.anInt = anInt;
}
}
This code:
public void basicUse() {
System.out.println("\n\n1. Demonstrating basic usage of Infinispan. This cache stores arbitrary Strings.");
Cache<String, ArrayList<Sensor>> cache = cacheManager.getCache("stockTickers", true);
cache.put("test", new ArrayList<>(List.of(new Sensor(1), new Sensor(2), new Sensor(3), new Sensor(4))));
// this fails
List<Sensor> test = cache.get("test");
}
yields in: Exception in thread "main" org.infinispan.commons.dataconversion.EncodingException: ISPN000495: ProtostreamTranscoder encountered error transcoding content because in this code, since in the example the array contains 4elements (4tags and 4 bytes arrays), the field count gives 8, throwing the error. If you only add one into the list the code works:
//this works
cache.put("test", new ArrayList<>(List.of(new Sensor(1))));
I've tried simple types, like a list of integers Cache<String, ArrayList<Integer>>
and it works because of the break in the switch