Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

TSerializer parameter of TConverter methodscannot be used generically when using an XML Serializer


TConverter.Write has a serializer Parameter S : TSerializer that is based on the base class. I can use this successfully to create a JSON payload with Super Object, but when I attempt to use the same code to create an XML Payload (TNativeXML). I get an invalid serializer state error.

Looking into this I can see that there is a RootValue default property for the XML Serializers that is not part of the base class and therefore makes the XML Serializer special in that they cannot be accessed generically. 

So for instance when I do the following:

S.BeginArray('SomeName'); The JSON Seriailzer works but the XML Serialzier does not because the XML Serializer is expecting to be used like this.

S['SomeName'].BeginArray('SomeName');  This Root Value property of the XML serializers breaks the generic nature of having and passing a base class to a method like TConverter.DoRead/DoWrite, and requires that I specifically now have code that checks the type of the TSerializer parameter and have a one off code branch that handles this scenario.

IMHO I should be able to use the S: TSerializer variable generically and not perform this function.


  • 5 Comments sorted by Votes Date Added
  • I guess there really wasn't a question there, sorry. Is it possible to use the XML serializer generically via the TSerializer base class as we can with the JSON serializers?

    If not can you please consider how you might remove the need to call the RootValue property and allow the XML serializer to be used generically?


    Todd Flora
    Retail Pro Inc.
  • Posts: 0 Accepted Answer Vote Up0Vote Down

    You have to use RootValue at a higher level, e.g. before passing serializer to your generic procedure, like this:


    Think about the fact that you have to have several different blocks of code, where you create and initialize your serializer objects. So, something there you have to use the RootValue too...

    While designing package I've though about this aspect, but there no other way to proceed.
  • This was not the answer I was hoping for.

    Thanks anyway.

  • Hi,

    Really, I can't understand your problem. Think about ['MyRoot'] just as parameter of serializer constructor.
    Otherwise, can you show me an example of your code, which is a proble for you...
Sign In or Register to comment.