]
Adrian Nistor updated IPROTO-33:
--------------------------------
Status: Pull Request Sent (was: Open)
Git Pull Request:
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}