<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>+1 for answering true for every simple setter selector as an addition for the implementation I proposed earlier. Sorry I forgot the setters!</p>
<p><br>
</p>
<p>For the purpose, I like to make much use of JsonObjects instead of first-class object instances in some scenarios, especially at the beginning of a project when it's an easy hack to mock not-yet implemented classes, or when communicating with a RESTful API.
 Thanks to dynamic forwarding (see JsonObject >> #doesNotUnderstand:), I can use these JsonObjects interchangeably (polymorphically) with first-class object instances. However, it is a common practice to check whether an object responds to a message before
 actually sending it, i.e. to determine its type or capabilities dynamically, which is done via #respondsTo:. To strengthen the interchangeability of JsonObject with first-class object instances, I'd like to send #respondsTo: to JsonObjects in order to find
 out whether it "has" a certain property, for instance:</p>
<p><br>
</p>
<p>newOrder respondsTo: #deadline "Check whether the order is an order limited-in-time or whether not. newOrder might be a subinstance of the (abstract) class Order, or a JsonObject."</p>
<p><br>
</p>
<p>For more context, see also this thread: <a href="http://forum.world.st/Should-you-override-doesNotUnderstand-and-respondsTo-together-td5110969.html" class="OWAAutoLink" id="LPlnk763312" previewremoved="true">http://forum.world.st/Should-you-override-doesNotUnderstand-and-respondsTo-together-td5110969.html</a></p>
<br>
<p>So a better implementation of JsonObject >> #respondsTo: might be the following:</p>
<p><br>
</p>
<p></p>
<div>respondsTo: aSymbol</div>
<div><br>
</div>
<div><span style="white-space:pre"></span>^ (super respondsTo: aSymbol)</div>
<div><span style="white-space:pre"></span>or: [aSymbol isSimpleGetter and: [self includesKey: aSymbol]]</div>
<div><span style="white-space:pre"></span>or: [aSymbol isSimpleSetter]</div>
<br>
<p></p>
<p>Provided that Json does not need to be compatible with older Squeak versions (the simple[GS]etter stuff is quite new). :-)</p>
<p><br>
</p>
<p>Best,</p>
<p>Christoph</p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel<br>
<b>Gesendet:</b> Montag, 9. November 2020 08:04:20<br>
<b>An:</b> squeak-dev<br>
<b>Betreff:</b> Re: [squeak-dev] I'd like to contribute to the JSON project</font>
<div> </div>
</div>
<div>
<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000">
Hi Levente.
<div><br>
</div>
<div>Sounds right. If an object can answer to some extra messages via #doesNotUnderstand:, one should also override #respondsTo:. It is like #= and #hash.</div>
<div><br>
</div>
<div>I did not know about #dictionaryClass:. That's a powerful hook.</div>
<div><br>
</div>
<div>Best,</div>
<div>Marcel</div>
<div class="mb_sig"></div>
<blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px">
<p style="color: #AAAAAA; margin-top: 10px;">Am 09.11.2020 03:07:54 schrieb Levente Uzonyi <leves@caesar.elte.hu>:</p>
<div style="font-family:Arial,Helvetica,sans-serif">Hi Christoph,<br>
<br>
On Sun, 8 Nov 2020, Christoph Thiede wrote:<br>
<br>
> Hi Levente,<br>
><br>
> would you mind to merge JSON-ct.41 (#respondsTo:) as well? This would be<br>
> great because I depend on this functionality in another project and<br>
> currently require your JSON fork in my baseline. :-)<br>
<br>
I cannot merge it because that would bring back long removed methods, and<br>
MC wouldn't allow me to reject those.<br>
But I can add the changes manually.<br>
If I'm not mistaken, it's just a single method JsonObject >> #respondsTo:.<br>
<br>
What is the purpose of that method?<br>
I'm asking because it has got no comment, so I'm not sure its <br>
implementation is correct.<br>
For example, should<br>
<br>
JsonObject new respondsTo: #foo:<br>
<br>
return false?<br>
What should the following return?<br>
<br>
JsonObject new<br>
foo: 1;<br>
respondsTo: #foo:<br>
<br>
Another question is whether it is generally useful or not?<br>
If it's not, you can still have the desired behavior by creating a <br>
subclass. E.g.:<br>
<br>
JsonObject subclass: #PseudoObject<br>
instanceVariableNames: ''<br>
classVariableNames: ''<br>
poolDictionaries: ''<br>
category: 'PseudoObject'<br>
<br>
<br>
PseudoObject >> respondsTo: aSymbol<br>
<br>
^ (super respondsTo: aSymbol)<br>
or: [self includesKey: aSymbol]<br>
<br>
<br>
(Json new<br>
dictionaryClass: PseudoObject;<br>
readFrom: '{"foo": 42}' readStream)<br>
respondsTo: #foo<br>
"==> true"<br>
<br>
<br>
Levente<br>
<br>
><br>
> Best,<br>
> Christoph<br>
><br>
><br>
><br>
> --<br>
> Sent from: http://forum.world.st/Squeak-Dev-f45488.html<br>
<br>
</div>
</blockquote>
</div>
</div>
</body>
</html>