Created
May 24, 2017 12:11
-
-
Save nkkarthik/f116e572be7e3ef3cd25c7d6eeb22d87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab( | |
group='org.codehaus.jackson', | |
module='jackson-mapper-asl', | |
version='1.9.11') | |
import org.codehaus.jackson.map.* | |
import org.codehaus.jackson.annotate.* | |
import groovy.transform.* | |
@Canonical | |
class MachineConfig { | |
int stock | |
boolean price | |
} | |
@Canonical | |
@JsonTypeName("setMachineConfig") | |
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) | |
class SetMachineConfigCommand { | |
@JsonUnwrapped MachineConfig config | |
} | |
command = ''' | |
{ | |
"setMachineConfig": { | |
"stock": 1, | |
"price": false | |
} | |
} | |
''' | |
println new ObjectMapper().readValue(command, SetMachineConfigCommand) | |
@Canonical | |
@JsonTypeName("getMachineConfig") | |
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) | |
class GetMachineConfigRequest { | |
@JsonUnwrapped MachineConfig config | |
} | |
request = ''' | |
{ | |
"getMachineConfig": { | |
"stock": 1, | |
"price": false | |
} | |
} | |
''' | |
println new ObjectMapper().readValue(request, GetMachineConfigRequest) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment