Groovy WMS script to convert object to JSON
- thecodingguy
- May 1
- 1 min read
Updated: May 2
This is simplified version of a Groovy script I used on JDA / Blue Yonder WMS envs to map WMS data into an object and then use the Jackson ObjectMapper class to convert it to JSON. This is a very simplified version of the script.
A SQL could be added at the beginning, such as [select * from ord] and the result set passed into the script. Then the set methods can be changed to set the ORDNUM and WH_ID from the values in the SQL results.
More fields could also be added to the Order class as well to generate a more complex JSON.
[[
public class Order
{
private String ordnum;
private String wh_id;
public String getOrdnum() {
return this.ordnum;
}
public void setOrdnum( String ordnum ) {
this.ordnum = ordnum;
}
public String getWh_id() {
return this.wh_id;
}
public void setWh_id( String wh_id ) {
this.wh_id = wh_id;
}
}
import com.fasterxml.jackson.databind.ObjectMapper;
ObjectMapper mapper = new ObjectMapper();
Order ord = new Order();
ord.setOrdnum( "TEST_ORDER" );
ord.setWh_id( "TEST_WH_ID" );
String jsonString = mapper.writeValueAsString( ord );
//String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString( ord );
output_string = jsonString;
output_string;
]]