You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "JoelGaechter (via GitHub)" <gi...@apache.org> on 2024/12/20 08:57:34 UTC

[I] [Bug]: unexpected data type for `List` fields in OPM

JoelGaechter opened a new issue, #1947:
URL: https://github.com/apache/plc4x/issues/1947

   ### 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.
   ```java
   @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 a 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
   
   - [X] plc4j
   - [ ] plc4go
   - [ ] plc4c
   - [ ] plc4net
   
   ### Protocols
   
   - [ ] AB-Ethernet
   - [ ] ADS /AMS
   - [ ] BACnet/IP
   - [ ] CANopen
   - [ ] DeltaV
   - [ ] DF1
   - [ ] EtherNet/IP
   - [ ] Firmata
   - [ ] KNXnet/IP
   - [ ] Modbus
   - [ ] OPC-UA
   - [ ] S7


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: unexpected data type for `List` fields in OPM

Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz closed issue #1947: [Bug]: unexpected data type for `List` fields in OPM
URL: https://github.com/apache/plc4x/issues/1947


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: unexpected data type for `List` fields in OPM

Posted by "JoelGaechter (via GitHub)" <gi...@apache.org>.
JoelGaechter commented on issue #1947:
URL: https://github.com/apache/plc4x/issues/1947#issuecomment-2559575818

   As off right now, these fields are se using the fallback behavior of `PlcEntityInterceptor::getTyped`:
   ```java
   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 needed as `PlcReadResponse::getAll...` returns a generic `Collection`. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org