Refactoring CRUD routines and thinking it would be really handy to have a way to push JSON into oData.
Wondering if this is built into wwBusiness and I'm not seeing the function?
oBus.oData = loJson is to invasive and thinking more about the interface to GATHER where LIKE and FIELDS EXCEPT are supported.
Any suggestions...
Generally it's a bad idea to serialize data directly into an object because 90% of the time there are values that the imported object is missing or hasn't set. You always want to be very careful with this including usage of SCATTER/GATHER for the very same reasons. You have to always make sure you leave the original objects values that aren't handled by input from the client intact.
You can probably use CopyObject()
(from wwutils.prg
) for copy the JSON result object to your data object, but you have the same issue described above.
+++ Rick ---
Have you created a utility to do something like aFields( tableName ) but for a JSON object ?
It seems like the VFM command LIST OBJECT loJson would work but it means writing out to a file and then parsing back into an array or an collection.
Once done very mush like Gather has a LIKE and EXCLUDE, a function could move the request data into oBus.oData with whatever sort of rules or validation were needed.
LIST OBJECT just seems like a hack at best, there must be a way to know the property names of the JSON object...
Like I said CopyObject()
does that in minmal capacity but there are lots of issues with this approach.
SCATTER GATHER only work on a single level, so that's rpetty easy. Copying an entire object graph though that's a lot more difficult when dealing with child object, arrays and collections.
+++ Rick ---
Wow - I'm truly very impressed...
After Windows Update restarted my machine, Visual Studio 2015 restarted with new Notifications. Guess who was sending me messages under the covers, Mr. Strahl did, a message that West-Wind WebConnect had an update that would be available for two more days. I wish I had a screen shot, I dismissed it before realizing VS does not keep a History of notifications. Got to admit, very cool that you found this hook into VS!
Looked at CopyObject, lots of code there I can use to create a method to move JSON into oData. Thanks...(and it only took telling me two times)