[infinispan-issues] [JBoss JIRA] (IPROTO-33) ClassCastException with Array of Enums
Gustavo Fernandes (JIRA)
issues at jboss.org
Wed Jul 19 10:23:00 EDT 2017
[ https://issues.jboss.org/browse/IPROTO-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13437643#comment-13437643 ]
Gustavo Fernandes commented on IPROTO-33:
-----------------------------------------
Hey [~anistor], the IPROTO project is not in sync with the released versions of protostream, so I cannot report issues against the correct version
> ClassCastException with Array of Enums
> --------------------------------------
>
> Key: IPROTO-33
> URL: https://issues.jboss.org/browse/IPROTO-33
> Project: Infinispan ProtoStream
> Issue Type: Bug
> Affects Versions: 4.0.0.Alpha5
> Reporter: Gustavo Fernandes
>
> The entity is defined as:
> {code:java}
> public class Account extends BaseMessage {
> public enum Currency {
> EUR, GBP, USD, BRL
> }
> ...
> private Currency[] currencies;
> ...
> }
> {code}
> Protofile:
> {code}
> message Account {
> ...
> /* @TypeId(43) */
> enum Currency {
> EUR = 0;
> GBP = 1;
> ...
> }
> repeated Currency currencies = 6;
> ...
> }
> {code}
> Marshaller:
> {code:java}
> public class AccountMarshaller implements MessageMarshaller<Account> {
> ...
> @Override
> public Account readFrom(ProtoStreamReader reader) throws IOException {
> ...
> Account.Currency[] currencies = reader.readArray("currencies", Account.Currency.class);
> Account account = new Account();
> ...
> account.setCurrencies(currencies);
> return account;
> }
> @Override
> public void writeTo(ProtoStreamWriter writer, Account account) throws IOException {
> ...
> writer.writeArray("currencies", account.getCurrencies(), Account.Currency.class);
> }
> }
> {code}
> When trying to marshal and unmarshall a message:
> {code:java}
> Account account = ...
> SerializationContext context = ...
> byte[] bytes = ProtobufUtil.toWrappedByteArray(context, account);
> // Throws CCE
> Account acc = ProtobufUtil.fromWrappedByteArray(context, bytes);
> {code}
> {noformat}
> java.lang.ClassCastException: java.lang.Long cannot be cast to [B
> at org.infinispan.protostream.impl.ProtoStreamReaderImpl.readCollection(ProtoStreamReaderImpl.java:374)
> at org.infinispan.protostream.impl.ProtoStreamReaderImpl.readArray(ProtoStreamReaderImpl.java:470)
> at org.infinispan.protostream.domain.marshallers.AccountMarshaller.readFrom(AccountMarshaller.java:33)
> at org.infinispan.protostream.domain.marshallers.AccountMarshaller.readFrom(AccountMarshaller.java:14)
> at org.infinispan.protostream.impl.MessageMarshallerDelegate.unmarshall(MessageMarshallerDelegate.java:113)
> at org.infinispan.protostream.WrappedMessage.readMessage(WrappedMessage.java:306)
> at org.infinispan.protostream.ProtobufUtil.fromWrappedByteArray(ProtobufUtil.java:154)
> at org.infinispan.protostream.ProtobufUtil.fromWrappedByteArray(ProtobufUtil.java:149)
> {noformat}
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)
More information about the infinispan-issues
mailing list