Usando o EclipSelink Moxy, você pode adicionar propriedades para manipular a saída.
public class Main {
public static void main(String[] args) {
Book book = new Book();
book.title = "hello";
JAXBContext context;
try {
context = JAXBContextFactory.createContext(new Class[] {Book.class}, null);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(book, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
Resultará em: {"book": {"title": "hello"}}
Ambos org.eclipse.persistence.moxy-2.5.1.jar e org.eclipse.persistence.core-2.5.1.jar são necessários no caminho de classe. Enquanto brincava com isso eu mesmo, eu encontrei: A resposta mais quente do JAXB. Especialmente Blaise Doughan responde onde muito útil. Procurar por
MarshallerProperties.MEDIA_TYPE, "application/json"
Para mais de seus exemplos.