3

I've written JSPRIT into a Jersey 2 RESTful server. I want our apps to call the server (POST) with a JSON string of a problem, feed the JSON request to JSPRIT and then output the best solution as JSON.

Everything works great.... except. I cannot work out how to output the solution to a JSON string. All the examples use VrpXMLWriter that writes to a disk file. I want to write the output as JSON to a string - not a file.

I've spent a few hours with my friend Google but have not worked it out.

Can someone help please ?

gmax
  • 39
  • 1
  • 5
  • 1
    You'll have to get to grips with building JSON in Java, the question is too broad to answer properly. However, have a look in `SolutionPrinter.java` which will give you an indication of how to obtain all of the data points – roganjosh Oct 05 '16 at 14:35
  • 1
    Sometimes the simplest advice is the best. Thanks roganjosh. SolutionPrinter gave me everything I needed to work it out. – gmax Oct 06 '16 at 03:59

1 Answers1

1

This is a bit old question, but hopefully the below solution can help someone:

import java.io.OutputStream;
import org.json.XML;

OutputStream xmlOutputStream = new VrpXMLWriter(problem, solutions, true).write();
String xmlOutput = xmlOutputStream.toString();
String jsonOutput = XML.toJSONObject(xmlOutput).toString();
Leo
  • 3,822
  • 3
  • 21
  • 26