简体   繁体   中英

Serde String[] in Kafka

I'm new in kafka. I am using the store builder and want to have a String[] of two elements as the value associated to the key. I set up the store like this:

StoreBuilder<KeyValueStore<String, String>> storeBuilder=Stores.keyValueStoreBuilder(
                Stores.persistentKeyValueStore(storeName),
                Serdes.String(),
                Serdes.String());
builder.addStateStore(storeBuilder);

When I call the method to have the data into the store:

String []oldValues = store.get(v.getVessel());

I receive this error:

Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class [Ljava.lang.String; (java.lang.String and [Ljava.lang.String; are in module java.base of loader 'bootstrap')

I should set the store like this:

StoreBuilder<KeyValueStore<String, String[]>>

but I don't know what to put instead of Serdes.String()

You would need to define your own Serializer, Deserializer and Serde subclasses to do this.

You can simply use a plain string with JSON deserialization to create a String array, or CSV

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM