[Pharo-dev] [ANN]: Little NeoJSON Helper

Sean P. DeNigris sean at clipperadams.com
Mon Apr 28 10:04:40 EDT 2014


"Assuming Neo-JSON-Core is loaded"
Gofer it
	smalltalkhubUser: 'SeanDeNigris' project: 'SeansPlayground';
	package: 'Neo-JSON-Utilities';
	load.

To aid in writing mappings, send "reader mapHelperFor: MyDomainClass", where
MyDomainClass need not even exist. This will halt inside the mapping, and
bring up an inspector on a NeoJSONMapHelper object. 

>From here, you can #generateInstVars to map the json keys to inst vars,
translating underscores to camel case.

Then you can inspect #mappingSnippet, which will give you the code to
replace "reader mapHelperFor: MyDomainClass" with the new mappings to inst
vars. For example:
	mapper for: DoDropletSize do: [ :m |
		m
			mapInstVars: #(name cpu slug memory id disk);
			mapInstVar: #costPerHour to: #cost_per_hour;
			mapInstVar: #costPerMonth to: #cost_per_month ].

It could be enhanced, especially with a UI to further customize the mappings
(e.g. maybe you want to map the boolean "required" key to a more
Smalltalkish "isRequired" inst var, but it makes the common cases a bit
easier.

HTH :)



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/ANN-Little-NeoJSON-Helper-tp4756763.html
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.




More information about the Pharo-dev mailing list