Question: How can I serve an RDF representation of a Java model via Spring MVC? 

I have JSON and XML representations working using Spring's content negotiation mechanisms and would like to do the same for RDF.

Answer: 
I'll preface this by mentioning that I don't know anything about Spring MVC. But, if you have a Java object you want to serialize as RDF, a library like [Empire](https://github.com/mhgrove/Empire) (I'm the author), might help you. You can annotate the object to specify what things should be turned into RDF and then use the `RdfGenerator` class to return back an RDF graph representing the object. You can then use something like the [RIO](http://openrdf.org) RDF writer from the Sesame framework to serialize the graph as whatever RDF serialization is requested.

I know that's not Spring MVC specific, but if you can get the OutputStream & the requested content-type, you should be able to make it work with Empire & Sesame's RIO.
In addition, you must add the `charset` parameter. [StringHttpMessageConverter](https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java) uses as default character encoding ISO-8859-1 unless you change it. When the output format has a fixed encoding different from ISO-8859-1 (e.g. UTF-8), it must be declared in `produces`. This behaviour is consistent with specs. For example, when the model contains non ASCII characters and it is encoded in `turtle`, the specification says that the media type [text/turtle](http://www.w3.org/TR/turtle/#sec-mediaReg) must contain the parameter `charset` with the value `UTF-8`. Otherwise, it is optional. 

```
  @RequestMapping(value = "your/service/location", method = RequestMethod.GET, 
        produces = { "text/turtle;charset=UTF-8"})
  public @ResponseBody String getModelAsTurtle() throws IOException {
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        RDFDataMgr.write(os, model, RDFFormat.TURTLE_PRETTY);
        return os.toString();
    }
  }

```