Last active
August 29, 2015 14:01
-
-
Save ghillairet/5d1c90f90af423d794a9 to your computer and use it in GitHub Desktop.
EMFJSON Usage
This file contains 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
ResourceSet resourceSet = new ResourceSetImpl(); | |
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("json", new JsResourceFactoryImpl()); | |
// | |
// Then create an object and add it to a resource. | |
// Give the resource a URI that will be path to the resulting json file. | |
// | |
Resource resource = resourceSet.createResource(URI.createURI("model.json")); | |
Map<String, Object> options = new HashMap<String, Object>(); | |
options.put(EMFJs.OPTION_INDENT_OUTPUT, true); | |
options.put(EMFJs.OPTION_SERIALIZE_TYPE, false); | |
LibraryShelf aShelf = LibraryFactory.eINSTANCE.createLibraryShelf(); | |
aShelf.setName("My Shelf"); | |
Book aBook = LibraryFactory.eINSTANCE.createBook(); | |
aBook.setTitle("EMF: Eclipse Modeling Framework (2nd Edition)"); | |
aBook.setNumPages(739); | |
aShelf.getItems().add(aBook); | |
resource.getContents().add(aShelf); | |
// | |
// The resource will be saved as JSON | |
// | |
resource.save(options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment