Skip to content

Instantly share code, notes, and snippets.

@ghillairet
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghillairet/5d1c90f90af423d794a9 to your computer and use it in GitHub Desktop.
Save ghillairet/5d1c90f90af423d794a9 to your computer and use it in GitHub Desktop.
EMFJSON Usage
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