[Pharo-users] NeoJSON mapping question

BrunoBB smalltalk at adinet.com.uy
Mon Feb 25 21:50:37 EST 2019


Hi,

The following implementation do what i want without the need to create a
class for each level of the JSON, however i really dislike my solution.
neoJsonMapping: mapper "class side"
	"Map the receiver to a json with <NeoJSONObjectMapping> <mapper>"
	mapper for: self do: [ :mapping |
		(mapping mapProperty: 'booking' getter: [:obj | obj locator] setter: [
:obj :value | obj setLocator: value]) valueSchema: self.
	].

 	mapper for: self do: [ :mapping |
		mapping mapProperty: '@locator' getter: [:obj | obj locator] setter: [
:obj :value | obj locator: value]
	]

The first part map 'booking' property to the class locator inst var. The
second part have access to the "second json level" and the value i'm looking
for.

But setLocator: anObject is the ugly thing :(
setLocator: anObject
	(anObject class == PmsJsonInput) ifTrue: [^locator := anObject locator].
	locator := anObject

I'm sure there must be another way to do this.

regards,
bruno



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html



More information about the Pharo-users mailing list