Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  Please, fix the incoherent use of generics in the Java SDK

    Posted 08-15-2025 17:43

    Hello,

    While reading through the code, and using the SDK I came across the NotificationListener interface (link to the file, in the latest release: 229.0.0).
    My point is the following: why is this interface marked as generically typed (NotificationListener<T>), when its methods do not returned object type with its type (T) but as ?.
    In fact it says "hey I listen to notifications of type Exemple, but I will receive a notification of an unknown type (Object), where I should receive an Exemple notification". This doesn't seem coherent at all.


    For this specific interface I would expect it to be like this:

    package com.mypurecloud.sdk.v2.extensions.notifications;
    
    public interface NotificationListener<T> {
        String getTopic();
        Class<T> getEventBodyClass();
        void onEvent(NotificationEvent<T> event);
    }

    This would be much more logical / coherent.

    By the way, I didn't dig in the code, but I think it should be fixed in all other interfaces/classes, if the same kind of thing happens anywhere else…


    Thank you in advance for your response.


    #PlatformSDK

    ------------------------------
    Gaël BLAISE
    National Bank of Canada
    ------------------------------


  • 2.  RE: Please, fix the incoherent use of generics in the Java SDK

    Posted 08-18-2025 12:02
    Edited by Jerome Saint-Marc 08-19-2025 08:53

    Hello,

    Have you also already seen this section of the Java SDK README (paragraph named "Handle incoming notification events")?

    The generic is meant to manage the different topic events (defined as classes in the Java SDK) listed in the Available Topics page. The notificationMappings.json file can be useful to find what class represents which topic.

    Regards,


    ------------------------------
    Jerome Saint-Marc
    Senior Development Support Engineer
    ------------------------------



  • 3.  RE: Please, fix the incoherent use of generics in the Java SDK

    Posted 08-19-2025 17:37

    Hello,

    Thank you for your answer, but this doesn't solve my point at all.
    Taking the exemple from the documentation, I'll try to highlight the enhancement that should be done, using comment:

    public class UserPresenceListener implements NotificationListener<PresenceEventUserPresence> {
        private String topic;
    
        public String getTopic() {
            return topic;
        }
    
        public Class<PresenceEventUserPresence> getEventBodyClass() {
            return PresenceEventUserPresence.class;
        }
    
        @Override
        // The problem is on this type. It shouldn't be `NotificationEvent<?>`, but `NotificationEvent<PresenceEventUserPresence>`
        public void onEvent(NotificationEvent<?> event) {
            // This would remove the necessity to cast the `event.getEventBody()` here ↓
            System.out.println("system presence -> " + ((PresenceEventUserPresence)event.getEventBody()).getPresenceDefinition().getSystemPresence());
        }
    
        public UserPresenceListener(String userId) {
            this.topic = "v2.users." + userId + ".presence";
        }
    }
    

    I hope the comments I added in the code explain better the situation.



    ------------------------------
    Gaël BLAISE
    National Bank of Canada
    ------------------------------