[Seaside] Failing test for #fromJson:
Tomas Kukol
tomas.kukol at gmail.com
Thu Jun 21 09:40:38 UTC 2012
Hello,
I am using Margitte-Json and Magritte-Tests-Json. MJTestPerson and
MJTestAddress are part of Magritte-Tests-Json package and these
classes have both magritte descriptions. There are codes for both
classes:
--- MJTestPerson (begin) ----------------------------------------
MJTestPerson >> favouriteHobby
^ favouriteHobby
MJTestPerson >> descriptionOtherHobbies
<magritteDescription>
^ MAMultipleOptionDescription new
accessor: #otherHobbies;
label: 'Other hobbies';
options: self class allHobbies;
priority: 50;
yourself
MJTestPerson >> address: anObject
address := anObject
MJTestPerson >> address
^ address
MJTestPerson >> favouriteHobby: anObject
favouriteHobby := anObject
MJTestPerson >> otherAddresses
^ otherAddresses
MJTestPerson >> descriptionOtherAddresses
<magritteDescription>
^ MAToManyRelationDescription new
accessor: #otherAddresses;
label: 'Other addresses';
classes: (Array with: MJTestAddress);
priority: 40;
yourself
MJTestPerson >> otherAddresses: anObject
otherAddresses := anObject
MJTestPerson >> descriptionFavouriteHobby
<magritteDescription>
^ MASingleOptionDescription new
accessor: #favouriteHobby;
label: 'Favourite hobby';
options: self class allHobbies;
priority: 30;
yourself
MJTestPerson >> name: anObject
name := anObject
MJTestPerson >> otherHobbies
^ otherHobbies
MJTestPerson >> descriptionName
<magritteDescription>
^ MAStringDescription new
accessor: #name;
label: 'Name';
priority: 10;
yourself
MJTestPerson >> descriptionAddress
<magritteDescription>
^ MAToOneRelationDescription new
accessor: #address;
label: 'Address';
classes: (Array with: MJTestAddress);
priority: 20;
yourself
MJTestPerson >> name
^ name
MJTestPerson >> otherHobbies: anObject
otherHobbies := anObject
--- MJTestPerson (end) ----------------------------------------
--- MJTestAddress (begin) ----------------------------------------
MJTestAddress >> postalCode
^ postalCode
MJTestAddress >> city: anObject
city := anObject
MJTestAddress >> city
^ city
MJTestAddress >> descriptionCity
<magritteDescription>
^ MAStringDescription new
accessor: #city;
label: 'City';
priority: 20;
yourself
MJTestAddress >> descriptionPostalCode
<magritteDescription>
^ MAStringDescription new
accessor: #postalCode;
label: 'Postal Code';
priority: 15;
yourself
MJTestAddress >> postalCode: anObject
postalCode := anObject
--- MJTestAddress (end) ----------------------------------------
BTW, there is a small code that allows to show all methods in OBBrowser.
--- OBCmdShowClassSource (begin) ----------------------------------------
OBCmdShowClassSource >> keystroke
^ $s
OBCmdShowClassSource >> label
^ 'Show class source code'
OBCmdShowClassSource >> execute
| class definition text |
class := target theClass.
text := WriteStream on: String new.
class methodDict
do: [ :each |
text nextPutAll: class name.
text nextPutAll: ' >> '.
text nextPutAll: each asString
]
separatedBy: [
text nextPut: Character cr.
text nextPut: Character cr
].
definition := OBClassDefinition environment: class environment
template: text contents.
requestor announce: (OBDefinitionChanged definition: definition)
OBCmdShowClassSource >> isActive
^ (requestor isSelected: target) and: [ target respondsTo: #theClass ]
--- OBCmdShowClassSource (end) ----------------------------------------
Regards,
Tomas
On Wed, Jun 20, 2012 at 5:02 PM, Philippe Marschall
<philippe.marschall at gmail.com> wrote:
> On Wed, Jun 20, 2012 at 2:23 PM, Tomas Kukol <tomas.kukol at gmail.com> wrote:
>> Hello,
>>
>> I have created a test for #fromJson: message.
>>
>> MJTestFromJson >> testFromJsonWithAddress
>> | person address |
>> person := MJTestPerson fromJson:
>> '{"Name":"Tomas","Address":{"PostalCode":"19800","City":"Prague"}}'.
>>
>> self assert: person name equals: 'Tomas'.
>> address := person address.
>> self assert: address isNil not.
>> self assert: address postalCode equals: '19800'.
>> self assert: address city equals: 'Prague'.
>>
>> But the test fails because it cannot find PostalCode in MJTestPerson
>> instace (should be probably in MJTestAddress). Is it a problem of my
>> #fromJson: usage or wrong implementation of JSON deserialization?
>
> Are you using Magritte-JSON? If you can you show us the descriptions,
> ideally attach the whole MJTestPerson class?
>
> Cheers
> Philippe
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
More information about the seaside
mailing list