Casting to System.Object

Posted by oedev on 04-Aug-2016 04:09

Hi All,

I'm looking to use the Newtonsoft JSON serialisation libaray (http://www.newtonsoft.com/json) to serialise an Openedge object to JSON.

The main method to serialise to JSON expects a System.Object parameter (http://www.newtonsoft.com/json/help/html/SerializingJSON.htm), so the class that I'm instantiating my object from inherits from System.Object;

CLASS ScreenUsage INHERITS System.Object:

However, when I serialise my object and message out the results, I get some very odd looking content;

---------------------------
Message
---------------------------
{"PHH":{"Handle":31528552,"IsAlive":true,"OpaqueId":1002}}
---------------------------
OK
---------------------------

1 - I'm assuming when I cast to System.Object, the resultant object only contains properties from SystemObject class and not my ScreenUsage class?

2 - Is there any other was of passing a System.Object type to the method so that I can all my properties serialised?

Thanks!

All Replies

Posted by Frank Meulblok on 04-Aug-2016 04:32

Don't know what OpenEdge release you're currently using, but if you're on 11.6 you should consider using the built-in serialization features (in particular the Progress.IO.JsonSerializer) instead.

Posted by oedev on 04-Aug-2016 05:48

Thanks Frank, should have mentioned that I'm on 10.2B. I did see mention of the in built option in the documentation, and look forward to using it once we upgrade later this year, but need an alternative in the short term. Thanks

Posted by Laura Stern on 04-Aug-2016 08:32

Your output is not so odd as it seems.  Anytime you inherit a .NET class from the ABL, a .NET class is generated that is the hybrid of the two.  It will always contain the fields you're seeing, PHH, IsAlive and OpaqueId.

Posted by oedev on 05-Aug-2016 02:54

Thanks for the explanation. So, the question is, is there anyway of passing a type of System.Object which includes my additional properties ? Thanks

Posted by Laura Stern on 05-Aug-2016 07:14

When you inherit from a .NET class, the only properties the .NET side will know about are properties that you wrote to satisfy a .NET interface.  It also knows about methods that override a .NET method.  But that isn't relevant for your scenario.  

Posted by adwild on 13-Jan-2017 05:28

[quote user="Laura Stern"]

When you inherit from a .NET class, the only properties the .NET side will know about are properties that you wrote to satisfy a .NET interface.

[/quote]

I use the Newtonsoft library (because it's far more advanced than Progress.IO.JsonSerializer). I found out that properties of type CHARACTER will be serialized, so for some reason these properties are known on the .NET side. Other data types are not serialized.

This thread is closed