PTV2 Profile json and xml generation from code

Deals with generic topics such as logging, framework and so on. If you are not sure where to place your topic just put it here.
Post Reply
hegedus.tibor
Posts: 13
Joined: Fri Jan 15, 2021 2:02 pm

PTV2 Profile json and xml generation from code

Post by hegedus.tibor »

Hi,

we are using ptv2 with csharp REST client (generated with NSwagCSharp code generator from the OpenApiReference).
This way we get the csharp object model of the RequestProfile class tree, annotated for json conversion.

But periodically we would like to generate from the most frequent settings a stored profile as well, which requires xml format as far as we know.
We tried to run xml serialization simply on the csharp objects mentioned above, but run into casing and other incompatibilities.

We worked this around by generating another csharp class tree from the profile xsd as well, which is xml annotated properly and mapping the two with a csharp object mapper library, AgileMapper.

Out tests show, that is is actually working now, but we wonder if there is an easier way, where we can use the same csharp profile object to generate both the json profile for the API and the xml profile for the storedProfile files without object mapping?

Best regards,
Tibor
User avatar
Bernd Welter
Site Admin
Posts: 2705
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: PTV2 Profile json and xml generation from code

Post by Bernd Welter »

Hello Tibor.

Oli drew my attention to this article about handling of profiles.

Does this help?

Bernd
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
hegedus.tibor
Posts: 13
Joined: Fri Jan 15, 2021 2:02 pm

Re: PTV2 Profile json and xml generation from code

Post by hegedus.tibor »

Hi Bernd,

thanks for the update.
As I understand this method works for PTV1 (we used it this way as well), but is not working with PTV2.

The PTV2 REST client does not accept xml snippet, but requires an object model of the profile snippet.

Br,
Tibor
User avatar
Bernd Welter
Site Admin
Posts: 2705
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: PTV2 Profile json and xml generation from code

Post by Bernd Welter »

Hi Tibor,

in xServer1 the profile mechanism is indeed using XML only - whether the surrounding request is XML or JSON.

So from what I understand you need to instantiate an object in your application and if needed export this into both JSON and XML.

Unfortunately my own programming skills aren't sufficient for this meta task. I did already run into obstacles such as
- derived classes aren't handled properly
- some attributes do not appear in the "export"

Maybe a request / search for XML handling in Stack Overflow would be helpful? This sounds more like a generic C# / JSON / XML issue - not necessarily related to PTV's object modell and so on.

Sorry - I don't want to surrender - on the other hand I don't want to waste your time with advice that isn't profound.

Bernd
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
Post Reply