Assuming you are using an annotation configuration for your MVC application, this might be quite simple. Using W3C Media Types for RDF Text Formats as a Guide for Content Type Specification, it is quite simple to enlarge an existing solution. The real question is, what is your desired type of serialization when creating an RDF query? If we use Jena as the base model, then supporting any of the standard serialization is trivial out of the box. Json is the only thing that helped me with difficulty, but you have already decided this.
As you can see, the implementation of serialization (using standard Jena and without additional libraries) is actually quite simple! The problem ultimately simply matches the correct serialization with the type of content provided.
EDIT 19 2014
, . , IANA Media Type registry, RDF1.1 N-Triples JSON-LD.
@Controller
public class SpecialController
{
public Model model = null;
@RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"application/x-javascript", "application/json", "application/ld+json"})
public @ResponseBody String getModelAsJson() {
}
@RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"application/xml", "application/rdf+xml"})
public @ResponseBody String getModelAsXml() {
}
@RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"application/n-triples"})
public @ResponseBody String getModelAsNTriples() {
try( final ByteArrayOutputStream os = new ByteArrayOutputStream() ){
model.write(os, "N-TRIPLE");
return os.toString();
}
}
@RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"text/turtle"})
public @ResponseBody String getModelAsTurtle() {
try( final ByteArrayOutputStream os = new ByteArrayOutputStream() ){
model.write(os, "TURTLE");
return os.toString();
}
}
@RequestMapping(value="your/service/location", method=RequestMethod.GET, produces={"text/n3"})
public @ResponseBody String getModelAsN3() {
try( final ByteArrayOutputStream os = new ByteArrayOutputStream() ){
model.write(os, "N3");
return os.toString();
}
}
}