Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: unexpected data type for List fields in OPM #1947

Open
1 of 16 tasks
JoelGaechter opened this issue Dec 20, 2024 · 1 comment
Open
1 of 16 tasks

[Bug]: unexpected data type for List fields in OPM #1947

JoelGaechter opened this issue Dec 20, 2024 · 1 comment
Labels

Comments

@JoelGaechter
Copy link

JoelGaechter commented Dec 20, 2024

What happened?

When trying to query multiple values as a collection using a single tag, as follows, the (inner) datatypes returned do not match the field.

@PlcTag("input-register:1:UINT[2]")
private List<Integer> registers;

The field on the returned (ByteBuddy proxy) instance would be of type List<PlcUINT>. The problem is that if we then want to use list elements as Integer, this causes a ClassCastException.

The expected behavior IMO would be that the list is of type List<Integer> similar as it works for single values, e.g, @PlcTag("input-register:1:UINT") => int.

Note:
When trying to use an array, e.g., int[] instead, the field can not be assigned at all, as the call returns a list.

Version

v0.12.0

Programming Languages

  • plc4j
  • plc4go
  • plc4c
  • plc4net

Protocols

  • AB-Ethernet
  • ADS /AMS
  • BACnet/IP
  • CANopen
  • DeltaV
  • DF1
  • EtherNet/IP
  • Firmata
  • KNXnet/IP
  • Modbus
  • OPC-UA
  • S7
@JoelGaechter
Copy link
Author

JoelGaechter commented Dec 23, 2024

As off right now, these fields are se using the fallback behavior of PlcEntityInterceptor::getTyped:

Object responseObject = response.getObject(sourceFieldName);
if (clazz.isAssignableFrom(responseObject.getClass())) {
    return responseObject;
}

The preferrable option would be to call the respective PlcReadResponse::getAll... instead of PlcReadResponse::getObject if the field type is a collection (or array). For this, the generic type might need to be determined though. While for arrays, this can be done using Class::getComponentType, for collections TypeToken might be the way to go. Additionally, if specific collection types should be supported, further processing might be required as PlcReadResponse::getAll... returns a generic Collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant