Now able to marshall HashMap Object

349 views
Skip to first unread message

Harshit Bhuva

unread,
Jan 17, 2022, 9:34:19 AM1/17/22
to WildFly
Hi Team,

I am using ProtoStreamMarshaller to put my data into remote infinispan cache.
While putting custom object, data is getting stored in remote infinispan cache and also marshaller classes have been created for those custom object.

But while putting hashmap into remote cache I am getting below error.
"No marshaller registered for object of Java type java.util.HashMap".
Also it is not poosible to create marshaller for hashmap.

Below are my code spnippet.

@AutoProtoSchemaBuilder(
                dependsOn = {
                        CommonTypes.class,
                        CommonContainerTypes.class
                },
                includeClasses = {
                        UserSession.class
                },
                schemaFileName = "cache.proto",
                schemaFilePath = "proto/")
public interface CacheInitalizer extends SerializationContextInitializer {
}


So while putting usersession into remote cache its value contains HashMap Object.
In that case it is failing.


Harshit Bhuva

unread,
Jan 18, 2022, 9:38:17 AM1/18/22
to WildFly
Hi Team,

I have tried using @ProtoAdaptor but it is working fine for ArrayList but not working for HashMap.
Below is my code snippet.


1. ArrayListAdaptor.java

@ProtoAdapter(ArrayList.class)
public class ArrayListAdaptor {

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

   @ProtoFactory
   ArrayListAdaptor(List<Object> authors)
   {
      this.authors = authors;
   }
}

2. MapAdaptor.java

@ProtoAdapter(Map.class)
public class MapAdapter
{
        @ProtoField(number = 1, javaType = Map.class)
        public Map<Object,Object> authorizationCache;

        @ProtoFactory
        MapAdapter(Map<Object,Object> authorizationCache)
        {
                this.authorizationCache = authorizationCache;
        }

        public MapAdapter()
        {
               
        }
       


Kindly help.

Paul Ferraro

unread,
Jan 18, 2022, 12:05:36 PM1/18/22
to WildFly
First, ProtoStream operates on concrete classes, so your @ProtoAdapter should use not an interface.
Second, your @ProtoField looks to be recursive - so that won't work.

Instead, you'll want to use a repeated field for each map entry.
You will then need similar ProtoStream instrumentation for a map entry, which contains 2 @ProtoFields for the key and value.

Reply all
Reply to author
Forward
0 new messages