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-DeserializationJim,
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
------------------------------
Original Message:
Sent: 08-10-2020 09:34
From: Jim Crespino
Subject: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently
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
Original Message:
Sent: 08-10-2020 05:38
From: Amauri De Oliveira
Subject: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently
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.
Original Message:
Sent: 08-10-2020 04:37
From: Amauri De Oliveira
Subject: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently
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.
Original Message:
Sent: 08-10-2020 01:19
From: Dmitry Artemov
Subject: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently
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
Original Message:
Sent: 08-09-2020 18:48
From: Amauri De Oliveira
Subject: Genesys Platform SDK JAVA - Parsing configuration server objects to JSON efficiently
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.
------------------------------