Search in sources :

Example 1 with JSONGeneratorBuilderOperation

use of org.whole.lang.json.util.JSONGeneratorBuilderOperation in project whole by wholeplatform.

the class JSONPersistencesTest method testParseAndGenerateWithBuilderOperation.

@Test
public void testParseAndGenerateWithBuilderOperation() throws Exception {
    IEntity sampleModel = JSONSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream("sample.json")));
    StringPersistenceProvider pp = new StringPersistenceProvider();
    JsonGenerator generator = new JsonFactory().createGenerator(pp.getOutputStream());
    generator.useDefaultPrettyPrinter();
    JSONGeneratorBuilderOperation op = new JSONGeneratorBuilderOperation(generator);
    new ModelTemplate(sampleModel).apply(op);
    generator.close();
    assertEquals(sampleString, pp.getStore());
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) JSONGeneratorBuilderOperation(org.whole.lang.json.util.JSONGeneratorBuilderOperation) Test(org.junit.Test)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 Test (org.junit.Test)1 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)1 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)1 JSONGeneratorBuilderOperation (org.whole.lang.json.util.JSONGeneratorBuilderOperation)1 IEntity (org.whole.lang.model.IEntity)1 ModelTemplate (org.whole.lang.templates.ModelTemplate)1