Eclipselink Moxy를 사용하면 출력을 조작하기 위해 속성을 추가 할 수 있습니다.
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();
}
}
}
{ "book": { "title": "hello"}}
둘 다 org.eclipse.persistence.moxy-2.5.1.jar 및 org.eclipse.persistence.core-2.5.1.jar가 클래스 경로에서 필요합니다. 이것을 직접 놀면서 나는 다음과 같이 달렸다. 가장 인기있는 JaxB 답변. 특히 Blaise Doughan은 매우 도움이되는 곳에서 대답합니다. 검색
MarshallerProperties.MEDIA_TYPE, "application/json"
그의 사례를 더 많이 위해.