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? Thanks for any information. Tomas Kukol _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
I'm just guessing, but I bet if you change "Address" to "address" in the JSON string it just might work.
I'm also posting this to the Magritte list just in case...
Happy Trails
John
On Wed, Jun 20, 2012 at 8:23 AM, Tomas Kukol <[hidden email]> wrote: Hello, _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
In reply to this post by Tomas Kukol
On Wed, Jun 20, 2012 at 2:23 PM, Tomas Kukol <[hidden email]> 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 [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
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 <[hidden email]> wrote: > On Wed, Jun 20, 2012 at 2:23 PM, Tomas Kukol <[hidden email]> 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 > [hidden email] > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
In an effort to redeem myself after making that totally idiotic statement in my prior post, I have updated Magritte-Json and Magritte-Tests-Json to make the additional test pass. Unfortunately I had to define kind: on the descriptions to get it to work. I really do not see any other way.
I also added another (failing) test for adding Other Addresses to the JSON string. Hope this helps. John
On Thu, Jun 21, 2012 at 5:40 AM, Tomas Kukol <[hidden email]> wrote: Hello, _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
On Sat, Jun 23, 2012 at 5:37 PM, John McKeon <[hidden email]> wrote:
> In an effort to redeem myself after making that totally idiotic statement in > my prior post, I have updated Magritte-Json and Magritte-Tests-Json to make > the additional test pass. Unfortunately I had to define kind: on the > descriptions to get it to work. I really do not see any other way. > I also added another (failing) test for adding Other Addresses to the JSON > string. Thanks for the contribution. I fixed this test and now everything should work. Cheers Philippe _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Free forum by Nabble | Edit this page |