I have this dictionary and want to map it to an object of a particular class.All dictionary keys must be matched by the same named instance variable of the object.
I assume this is a normal procedure? What is the general way to achieve it?
Consider doing something like this:
dict := { #x -> 5 . #y -> 6 } asDictionary. "dictionary as you described" basicObj := Point basicNew. "basic instance of your object" dict keysAndValuesDo: [ :key :val | basicObj instVarNamed: key put: val ]. ^ basicObj
This is a really generic template. It is often used in serialization and materialization. You can find an implementation in STON
Source: https://habr.com/ru/post/1627038/More articles:Packages installed only in Python 2.7, but not in 3.5 - pythonUnit testing in Django - where to draw a line? - djangoHow to add one leaf marker to several groups? - javascriptLoading javascript assets from integration tests (Play / Selenium) - selenium-webdriverProtractor - pressing and sendingKlavins do not work - javascriptUsing Sitemesh in Grails 3 - sitemeshJackson: get the whole object in a custom field JsonDeserializer - javaAssignment of tuples of related types, why is it allowed only through explicit assignment of a member? (Error: Cannot Express Tuple Conversion) - tuplesQuick use of 'is' for function type, compiler behavior differs from runtime - functionCheck if keyword arguments exist in Julia - julia-langAll Articles