Jeevanantham
Jeevanantham

Reputation: 1032

infinispan 10.1 No marshaller registered for Java type java.util.ArrayList

While try to store the list object in the infinispan cache is throwing the error. I have referred some forums and included whitelist of list class too, but still getting the same error.

Note: Server hosted remotely

Imports

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.infinispan.client.hotrod.DefaultTemplate;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.commons.api.CacheContainerAdmin;

Code:

// Setup up a clustered cache manager
    ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer().host("127.0.0.1").port(11322).addJavaSerialWhiteList("java.util.List","java.util.ArrayList");
    // Connect to the server
    RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
    // Create test cache, if such does not exist
    cacheManager.administration().withFlags(CacheContainerAdmin.AdminFlag.VOLATILE).getOrCreateCache("test123", DefaultTemplate.DIST_SYNC);
    // Obtain the remote cache
    RemoteCache<String, List<String>> cache = cacheManager.getCache("test123");
    List<String> test = new ArrayList();
    cache.put("key", test);

Exception

Exception in thread "main" java.lang.IllegalArgumentException: No marshaller registered for Java type java.util.ArrayList
at org.infinispan.protostream.impl.SerializationContextImpl.getMarshallerDelegate(SerializationContextImpl.java:279)
at org.infinispan.protostream.WrappedMessage.writeMessage(WrappedMessage.java:240)
at org.infinispan.protostream.ProtobufUtil.toWrappedByteArray(ProtobufUtil.java:181)
at org.infinispan.protostream.ProtobufUtil.toWrappedByteArray(ProtobufUtil.java:176)
at org.infinispan.commons.marshall.ProtoStreamMarshaller.objectToBuffer(ProtoStreamMarshaller.java:69)
at org.infinispan.commons.marshall.AbstractMarshaller.objectToByteBuffer(AbstractMarshaller.java:70)
at org.infinispan.client.hotrod.marshall.MarshallerUtil.obj2bytes(MarshallerUtil.java:99)

Upvotes: 3

Views: 4067

Answers (2)

Ryan Emerson
Ryan Emerson

Reputation: 406

Unfortunately the ProtoStream marshaller does not currently support the direct marshalling of ArrayList, but this is planned for a subsequent ProtoStream release IPROTO-118.

To marshall ArrayList, or any Collection implementation, with Infinispan's default Protostream marshaller, it's necessary to wrap the collection in a user defined class and add it as a field. For example the following class allows ArrayLists to be stored:

public class Book {

   @ProtoField(number = 1, collectionImplementation = ArrayList.class)
   final List<String> authors;

   @ProtoFactory
   Book(List<String> authors) {
      this.authors = authors;
   }
}

Upvotes: 2

Jeevanantham
Jeevanantham

Reputation: 1032

Working after added the .marshaller(new JavaSerializationMarshaller()). Hope this change is correct if any better option available please post it

builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT).marshaller(new JavaSerializationMarshaller()).addJavaSerialWhiteList("java.util.List","java.util.ArrayList");

Upvotes: 3

Related Questions