FYI: 4D-Objects - Embedded Objects --> Save as file

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
G’day,

I tried the following (pseudo code):

Create an object
Fill the object with some stuff

Create another object and filled it with stuff including a picture

Put the second object into the first.

JSON Stringify($MyGreatObj)

Save objectText to file

Opened the file in BBEdit:
{
        "Para1": "2019-09-24",
        "Para2": 36170,
        "ActivationCode": "activationCode",
        "Embeded": {
                "SomePict": "[object Picture]",
                "someText": "TestText",
                "aRealNumber": 3.1415926535898
        }
}

************ NOW

$ObjText := Document To Text

$TestObject:=JSON Parse($ObjText)


$TestText:=$TestObject.Embeded.sometext

TestPict:=$TestObject.Embeded.somePict

Both variables are EMPTY!


***** Next STEP


$EmbeddedObj:=$TestObject.Embeded

$TestText:=$EmbeddedObj.sometext


$EmbeddedObj contains the object but $TestText is empty again.

The picture is a total lost!


So, I think 4D-Objects need more time (another 25 years?) to catch up with ObjectTools…

A command like OB To BLOB would be a nice point to start.

My 2¢

Cheers
Jörg
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
I haven’t tried your. Ode but dotted notation is case sensitive. Could
that be the issue?

On Mon, Sep 23, 2019 at 6:35 PM Jörg Knebel via 4D_Tech <
[hidden email]> wrote:

> G’day,
>
> I tried the following (pseudo code):
>
> Create an object
> Fill the object with some stuff
>
> Create another object and filled it with stuff including a picture
>
> Put the second object into the first.
>
> JSON Stringify($MyGreatObj)
>
> Save objectText to file
>
> Opened the file in BBEdit:
> {
>         "Para1": "2019-09-24",
>         "Para2": 36170,
>         "ActivationCode": "activationCode",
>         "Embeded": {
>                 "SomePict": "[object Picture]",
>                 "someText": "TestText",
>                 "aRealNumber": 3.1415926535898
>         }
> }
>
> ************ NOW
>
> $ObjText := Document To Text
>
> $TestObject:=JSON Parse($ObjText)
>
>
> $TestText:=$TestObject.Embeded.sometext
>
> TestPict:=$TestObject.Embeded.somePict
>
> Both variables are EMPTY!
>
>
> ***** Next STEP
>
>
> $EmbeddedObj:=$TestObject.Embeded
>
> $TestText:=$EmbeddedObj.sometext
>
>
> $EmbeddedObj contains the object but $TestText is empty again.
>
> The picture is a total lost!
>
>
> So, I think 4D-Objects need more time (another 25 years?) to catch up with
> ObjectTools…
>
> A command like OB To BLOB would be a nice point to start.
>
> My 2¢
>
> Cheers
> Jörg
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

--
--
Douglas von Roeder
949-910-4084
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
Auto correct…

“your code”

On Mon, Sep 23, 2019 at 6:41 PM Douglas von Roeder <[hidden email]>
wrote:

> I haven’t tried your. Ode but dotted notation is case sensitive. Could
> that be the issue?
>
> On Mon, Sep 23, 2019 at 6:35 PM Jörg Knebel via 4D_Tech <
> [hidden email]> wrote:
>
>> G’day,
>>
>> I tried the following (pseudo code):
>>
>> Create an object
>> Fill the object with some stuff
>>
>> Create another object and filled it with stuff including a picture
>>
>> Put the second object into the first.
>>
>> JSON Stringify($MyGreatObj)
>>
>> Save objectText to file
>>
>> Opened the file in BBEdit:
>> {
>>         "Para1": "2019-09-24",
>>         "Para2": 36170,
>>         "ActivationCode": "activationCode",
>>         "Embeded": {
>>                 "SomePict": "[object Picture]",
>>                 "someText": "TestText",
>>                 "aRealNumber": 3.1415926535898
>>         }
>> }
>>
>> ************ NOW
>>
>> $ObjText := Document To Text
>>
>> $TestObject:=JSON Parse($ObjText)
>>
>>
>> $TestText:=$TestObject.Embeded.sometext
>>
>> TestPict:=$TestObject.Embeded.somePict
>>
>> Both variables are EMPTY!
>>
>>
>> ***** Next STEP
>>
>>
>> $EmbeddedObj:=$TestObject.Embeded
>>
>> $TestText:=$EmbeddedObj.sometext
>>
>>
>> $EmbeddedObj contains the object but $TestText is empty again.
>>
>> The picture is a total lost!
>>
>>
>> So, I think 4D-Objects need more time (another 25 years?) to catch up
>> with ObjectTools…
>>
>> A command like OB To BLOB would be a nice point to start.
>>
>> My 2¢
>>
>> Cheers
>> Jörg
>> **********************************************************************
>> 4D Internet Users Group (4D iNUG)
>> Archive:  http://lists.4d.com/archives.html
>> Options: https://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:[hidden email]
>> **********************************************************************
>
> --
> --
> Douglas von Roeder
> 949-910-4084
>
--
--
Douglas von Roeder
949-910-4084
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
In reply to this post by 4D Tech mailing list
On Sep 24, 2019, at 4:29 PM, Jörg Knebel wrote:

> I tried the following (pseudo code):
>
> Create an object
> Fill the object with some stuff
>
> Create another object and filled it with stuff including a picture
>
> Put the second object into the first.
>
> JSON Stringify($MyGreatObj)
>
> Save objectText to file
>
> Opened the file in BBEdit:
> {
>    "Para1": "2019-09-24",
>    "Para2": 36170,
>    "ActivationCode": "activationCode",
>    "Embeded": {
>        "SomePict": "[object Picture]",
>        "someText": "TestText",
>        "aRealNumber": 3.1415926535898
>    }
> }
>
> ************ NOW
>
> $ObjText := Document To Text
>
> $TestObject:=JSON Parse($ObjText)
>
>
> $TestText:=$TestObject.Embeded.sometext
>
> TestPict:=$TestObject.Embeded.somePict
>
> Both variables are EMPTY!

The text variable is empty because object property names are case sensitive. Try “someText” for the name instead of “sometext”.

Picture object properties only store a reference to the picture, hence the “[object Picture]” property value. JSON Stringify command does not encode picture properties, you have to do that. You can write a wrapper method for JSON Stringify and JSON Parse to handle this situation if you need to do this often.

Tim

Sent from my iPad
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
Tim,
Do you have to Base64 encode the picture to store it in the JSON file?

On Tue, Sep 24, 2019 at 10:28 AM Tim Nevels via 4D_Tech <
[hidden email]> wrote:

> Picture object properties only store a reference to the picture, hence the
> “[object Picture]” property value. JSON Stringify command does not encode
> picture properties, you have to do that. You can write a wrapper method for
> JSON Stringify and JSON Parse to handle this situation if you need to do
> this often.


--
Kirk Brooks
San Francisco, CA
=======================

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
In reply to this post by 4D Tech mailing list
> Save objectText to file
>
> Opened the file in BBEdit:
> {
> "Para1": "2019-09-24",
> "Para2": 36170,
> "ActivationCode": "activationCode",
> "Embeded": {
> "SomePict": "[object Picture]",
> "someText": "TestText",
> "aRealNumber": 3.1415926535898
> }
> }
>
> ************ NOW
>
> $ObjText := Document To Text
>
> $TestObject:=JSON Parse($ObjText)
>
>
> $TestText:=$TestObject.Embeded.sometext

Property names are case-sensitive. That why this one failed.


> TestPict:=$TestObject.Embeded.somePict

https://doc.4d.com/4Dv17R5/4D/17-R5/Data-Types.300-4128319.en.html <https://doc.4d.com/4Dv17R5/4D/17-R5/Data-Types.300-4128319.en.html>

When exposed as text in the debugger or exported to JSON, picture object properties print "[object Picture]”.


> So, I think 4D-Objects need more time (another 25 years?) to catch up with ObjectTools…

Usually it only takes 10-15 years for them to catch up. 😁


> A command like OB To BLOB would be a nice point to start.

That would be pretty trivial to write yourself.

- Aparajita
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
In reply to this post by 4D Tech mailing list
On Sep 24, 2019, at 8:00 PM, Kirk Brooks wrote:

> Do you have to Base64 encode the picture to store it in the JSON file?

I would PICTURE TO BLOB and then BASE64 ENCODE the blob to create a text representation of the picture. Reverse the process to bring it back.

Tim

Sent from my iPad
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
Tim,

On Tue, Sep 24, 2019 at 2:32 PM Tim Nevels via 4D_Tech <[hidden email]>
wrote:

> On Sep 24, 2019, at 8:00 PM, Kirk Brooks wrote:
> > Do you have to Base64 encode the picture to store it in the JSON file?
>
> I would PICTURE TO BLOB and then BASE64 ENCODE the blob to create a text
> representation of the picture. Reverse the process to bring it back.


I suppose that would work for just about any kind of document wouldn't it?

--
Kirk Brooks
San Francisco, CA
=======================

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
In reply to this post by 4D Tech mailing list


> On 25 Sep 2019, at 04:59 AEST, Aparajita Fishman via 4D_Tech <[hidden email]> wrote:
>
> Property names are case-sensitive. That why this one failed.

I already figured this out.



>> So, I think 4D-Objects need more time (another 25 years?) to catch up with ObjectTools…
>
> Usually it only takes 10-15 years for them to catch up. 😁

Well, that should be enough time to do a proper job - don’t you think? 🤪


>> A command like OB To BLOB would be a nice point to start.
>
> That would be pretty trivial to write yourself.

Of cause it would, but there are two obstacles in the way:

1. I’m a bloody lazy bustard
2. There is a thing available right now that works and you might be aware of it, it’s called “ObjectTools”. 😎


In conjunction with all this, I’m wondering for how long ObjectTools will be maintained and would there be an early warning when/if support will cease… 🤔


Cheers
Jörg
   
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: FYI: 4D-Objects - Embedded Objects --> Save as file

4D Tech mailing list
In reply to this post by 4D Tech mailing list


> On 25 Sep 2019, at 07:32 AEST, Tim Nevels via 4D_Tech <[hidden email]> wrote:

> I would PICTURE TO BLOB and then BASE64 ENCODE the blob to create a text representation of the picture. Reverse the process to bring it back.

That sounds like a plan.

Thanks
Cheers
Jörg
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************