Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protobuf encoding marshling is not working when in a Java collection is used in the value part of the map #182

Open
NunuM opened this issue Dec 9, 2022 · 0 comments

Comments

@NunuM
Copy link

NunuM commented Dec 9, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant