Last active
January 2, 2016 16:39
-
-
Save rschumm/8331871 to your computer and use it in GitHub Desktop.
Marshallen einer Objektstruktur mit JAXB zu json.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void marshallToFile(Katalog katalog, File jsonFile) throws JAXBException, PropertyException { | |
// Marshalling... | |
JAXBContext context = JAXBContext.newInstance(PoGeVoKatalog.class); | |
Marshaller m = context.createMarshaller(); | |
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); | |
m.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); | |
m.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); | |
m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true); | |
m.marshal(katalog, System.out); | |
m.marshal(katalog, jsonFile); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.eclipse.persistence</groupId> | |
<artifactId>org.eclipse.persistence.moxy</artifactId> | |
<version>2.5.1</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
für das json-Marshallen wird die Bibliothek MOXy verwendet, da die Standart-JAXB das anscheinend nicht kann.
Das wird druch das Property jaxb.properties gesteuert.