Web Connection
wwBusiness Function JSONToData(loJSON,ExceptionList)
Gravatar is a globally recognized avatar based on your email address. wwBusiness Function JSONToData(loJSON,ExceptionList)
  Harvey Mushman
  All
  Feb 12, 2018 @ 02:40pm

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...

Gravatar is a globally recognized avatar based on your email address. re: wwBusiness Function JSONToData(loJSON,ExceptionList)
  Rick Strahl
  Harvey Mushman
  Feb 13, 2018 @ 12:57pm

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 ---

Gravatar is a globally recognized avatar based on your email address. re: wwBusiness Function JSONToData(loJSON,ExceptionList)
  Harvey Mushman
  Rick Strahl
  Feb 13, 2018 @ 05:22pm

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...

Gravatar is a globally recognized avatar based on your email address. re: wwBusiness Function JSONToData(loJSON,ExceptionList)
  Rick Strahl
  Harvey Mushman
  Feb 14, 2018 @ 07:28pm

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 ---

Gravatar is a globally recognized avatar based on your email address. re: wwBusiness Function JSONToData(loJSON,ExceptionList)
  Harvey Mushman
  Rick Strahl
  Feb 15, 2018 @ 07:25am

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)

Gravatar is a globally recognized avatar based on your email address. re: wwBusiness Function JSONToData(loJSON,ExceptionList)
  Rick Strahl
  Harvey Mushman
  Feb 17, 2018 @ 02:03pm

Why would you need to change anything about CopyObject? DeserlizeJson() produces an object - you just push that into CopyObject() to do its thing.

+++ Rick ---

© 1996-2024