Genesys Engage on-premises

 View Only
Discussion Thread View
  • 1.  Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently

    Posted 08-09-2020 18:49
    Hello all.

    Has anybody found a clever way to parse platform sdk(java) configuration objects to JSON efficiently ? while dealing with this I wrote my own simple object parser but its becoming more and more complex. I'm wondering if there is a clever way maybe already embedded in PSDK or something easy to get the job done.

    I tried something with "Jackson" but could not get it to work properly with PSDK.

    Thanks in advance,
    #GenesysEngageDev

    ------------------------------
    Amauri De Oliveira
    NTT Australia Pty Ltd.
    ------------------------------


  • 2.  RE: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently

    Posted 08-10-2020 01:19
    All our tasks solved with the help of Google GSON (https://github.com/google/gson).  May be this will suit you too.

    ------------------------------
    Dmitry Artemov
    Mobile Telesystems
    ------------------------------



  • 3.  RE: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently

    Posted 08-10-2020 04:38
    Thanks Dmitry.

    Reading their documentation i found the following limitation that resembles to an issue that I had before I implement my own Genesys cfgObject parser

    https://github.com/google/gson/blob/master/UserGuide.md
    Note that you can not serialize objects with circular references since that will result in infinite recursion.

    I noticed some objects with circular reference. Have you found a way to at least limit the "deepness" of your recursion on these scenarios ?


    ------------------------------
    Amauri De Oliveira
    NTT Australia Pty Ltd.
    ------------------------------



  • 4.  RE: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently

    Posted 08-10-2020 05:38
    Hello again.

    I gave it a go passing a CfgApplication and a CfgHost to "Gson", something like:
    Gson gs = new Gson();
    responses = gs.toJson(object);


    and both returned the same exception:

    java.lang.IllegalArgumentException: class com.genesyslab.platform.configuration.protocol.metadata.CfgDescriptionObject declares multiple JSON fields named typejava.lang.IllegalArgumentException: class com.genesyslab.platform.configuration.protocol.metadata.CfgDescriptionObject declares multiple JSON fields named type at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:172) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:56) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245) at com.google.gson.Gson.toJson(Gson.java:704) at com.google.gson.Gson.toJson(Gson.java:683) at com.google.gson.Gson.toJson(Gson.java:638) at com.google.gson.Gson.toJson(Gson.java:618) at com.genesyslab.platform.MainArgs.main(MainArgs.java:112)

    I'm guessing that the reason is the fact that CfgDescriptionObject has fields already declared in other classes, however still not very clear.


    ------------------------------
    Amauri De Oliveira
    NTT Australia Pty Ltd.
    ------------------------------



  • 5.  RE: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently

    GENESYS
    Posted 08-10-2020 09:34
    The Platform SDK has its own serializer built in to convert PSDK object to JSON.  Check out the PsdkJsonSerializer class as a starting point.  This is what our own Genesys Web Services, which is built on top of the Platform SDK, uses to serialize and deserialize JSON.  You'll probably want to check out the createConfServerSerializer() that knows how to work specifically with objects from Config Server.

    ------------------------------
    Jim Crespino
    Senior Director, Developer Evangelism
    Genesys
    https://developer.genesys.com
    ------------------------------



  • 6.  RE: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently

    Posted 08-11-2020 01:15
    Hello !

    Amauri,
    Quite right, we had the same error.
    We customized OOTB GSON following the documentation
    https://sites.google.com/site/gson/gson-user-guide#TOC-Custom-Serialization-and-Deserialization

    Jim,
    We tried PsdkJsonSerializer, but failed.
    In docs "... serializes Platform SDK message to JSON string  ..." therefore we use GSON.
    Are we misunderstanding ?
    Could you show us our mistake ?
    Sample code is below.


    ConfServerProtocol confServerProtocol = new ConfServerProtocol(new Endpoint ....
    ....
    IConfService _service = ConfServiceFactory.createConfService(confServerProtocol);
    ...
    CfgApplicationQuery cfgApplicationQuery = new CfgApplicationQuery(_service);
    cfgApplicationQuery.setName("SIP_server_name");
    CfgApplication cfgApplication = cfgApplicationQuery.executeSingleResult();
    ...
    PsdkJsonSerializer psdkJsonSerializer = PsdkJsonSerializer.createConfServerSerializer();
    System.out.println("----------\n" + psdkJsonSerializer.serialize(cfgApplication));

    Caused by: com.fasterxml.jackson.databind.JsonMappingException:
    Infinite recursion (StackOverflowError) (through reference chain:
    com.genesyslab.platform.configuration.protocol.metadata.CfgDescriptionObject["attributes"]->java.util.LinkedList[0]->com.genesyslab.platform.configuration.protocol.metadata.CfgDescriptionAttributeInteger["parent"]->com.genesyslab.platform.configuration.protocol.metadata.CfgDescriptionObject["attributes"]->
    .....​​

    ------------------------------
    Dmitry Artemov
    Mobile Telesystems
    ------------------------------



  • 7.  RE: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently

    Posted 08-11-2020 01:25
    Hello again !

    Sorry, I forgot to add this
    "... Frequently Asked Questions
    Q: The KV lists can contain pointers to outer KVlists, creating circular dependencies. Will such structures be
    serialized/deserialized?
    A: No. Platform SDK does not support sending or receiving such structures.  ..."
    from en-PSDK-9.0.x-Developer-book.pdf

    ------------------------------
    Dmitry Artemov
    Mobile Telesystems
    ------------------------------



  • 8.  RE: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently

    Posted 08-11-2020 01:46
    Thanks for advising @Jim Crespino and @Dmitry Artemov

    @Dmitry Artemov I will review the link you sent above and decide if its worth "customize a third party library" at this point or keep going with my custom parser.  if you could leave a commend advising your effort in hours to customize it as per your needs that would be great....

    @Jim Crespino​​​, I was about to say exactly the same thing mentioned by @Dmitry Artemov, the JSON parser embedded in PSDK seems useful only to convert protocol messages and similar type of things but does not include anything inside the package "com.genesyslab.platform.applicationblocks.com.objects" and few other ones as well. Please let us know if we are missing something.


    ​​

    ------------------------------
    Amauri De Oliveira
    NTT Australia Pty Ltd.
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources